|
|
7990b5 |
From 8390d1d432330e143832734d5799528013e79178 Mon Sep 17 00:00:00 2001
|
|
|
7990b5 |
From: Dmitri Pal <dpal@redhat.com>
|
|
|
7990b5 |
Date: Mon, 23 Sep 2013 16:03:30 -0400
|
|
|
7990b5 |
Subject: [PATCH] Trim trailing spaces
|
|
|
7990b5 |
|
|
|
7990b5 |
This patch addressed issue https://fedorahosted.org/sssd/ticket/2095
|
|
|
7990b5 |
The new parser in fact stopped trimming trailing spaces.
|
|
|
7990b5 |
This is now corrected.
|
|
|
7990b5 |
---
|
|
|
7990b5 |
ini/ini.d/real.conf | 2 +-
|
|
|
7990b5 |
ini/ini_parse.c | 7 ++++
|
|
|
7990b5 |
ini/ini_parse_ut.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
7990b5 |
3 files changed, 108 insertions(+), 1 deletion(-)
|
|
|
7990b5 |
|
|
|
7990b5 |
diff --git a/ini/ini.d/real.conf b/ini/ini.d/real.conf
|
|
|
7990b5 |
index 32bc9dae0c40ce46dc4c375963b5d0cf2a05e17b..1e155b820061001695d85edfeca1819e799e2a4b 100644
|
|
|
7990b5 |
--- a/ini/ini.d/real.conf
|
|
|
7990b5 |
+++ b/ini/ini.d/real.conf
|
|
|
7990b5 |
@@ -40,7 +40,7 @@ legacy = FALSE
|
|
|
7990b5 |
enumerate = 3
|
|
|
7990b5 |
|
|
|
7990b5 |
[domains/EXAMPLE.COM]
|
|
|
7990b5 |
-description = Example domain served by IPA
|
|
|
7990b5 |
+description = Example domain served by IPA
|
|
|
7990b5 |
provider = ipa
|
|
|
7990b5 |
server = ipaserver1.example.com
|
|
|
7990b5 |
server = ipabackupserver.example.com
|
|
|
7990b5 |
diff --git a/ini/ini_parse.c b/ini/ini_parse.c
|
|
|
7990b5 |
index 60ef1169986f2ea27596931ebf16fab166c71937..9a1c0ec63013adb986b627c977c9759c1d5a210e 100644
|
|
|
7990b5 |
--- a/ini/ini_parse.c
|
|
|
7990b5 |
+++ b/ini/ini_parse.c
|
|
|
7990b5 |
@@ -968,6 +968,13 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action)
|
|
|
7990b5 |
full_len--;
|
|
|
7990b5 |
}
|
|
|
7990b5 |
|
|
|
7990b5 |
+ /* Trucate trailing spaces */
|
|
|
7990b5 |
+ /* Make sure not to step before the beginning */
|
|
|
7990b5 |
+ while (full_len && isspace(str[full_len - 1])) {
|
|
|
7990b5 |
+ str[full_len - 1] = '\0';
|
|
|
7990b5 |
+ full_len--;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
/* Check if we have the key */
|
|
|
7990b5 |
if (*(str) == '=') {
|
|
|
7990b5 |
po->last_error = ERR_NOKEY;
|
|
|
7990b5 |
diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c
|
|
|
7990b5 |
index 32c59e7a3a36a5b719620ae42cf070154d4eb416..2655d7e8e11a391db324a9c022004f7cbbeb092e 100644
|
|
|
7990b5 |
--- a/ini/ini_parse_ut.c
|
|
|
7990b5 |
+++ b/ini/ini_parse_ut.c
|
|
|
7990b5 |
@@ -2650,6 +2650,105 @@ int space_test(void)
|
|
|
7990b5 |
return EOK;
|
|
|
7990b5 |
}
|
|
|
7990b5 |
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+int trim_test(void)
|
|
|
7990b5 |
+{
|
|
|
7990b5 |
+ int error;
|
|
|
7990b5 |
+ struct ini_cfgfile *file_ctx = NULL;
|
|
|
7990b5 |
+ struct ini_cfgobj *ini_config = NULL;
|
|
|
7990b5 |
+ char **error_list = NULL;
|
|
|
7990b5 |
+ char infile[PATH_MAX];
|
|
|
7990b5 |
+ char *srcdir = NULL;
|
|
|
7990b5 |
+ const char *value;
|
|
|
7990b5 |
+ struct value_obj *vo = NULL;
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ INIOUT(printf("\n\n<==== TRIM TEST START =====>\n"));
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ srcdir = getenv("srcdir");
|
|
|
7990b5 |
+ snprintf(infile, PATH_MAX, "%s/ini/ini.d/real.conf",
|
|
|
7990b5 |
+ (srcdir == NULL) ? "." : srcdir);
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ INIOUT(printf("Reading file %s\n", infile));
|
|
|
7990b5 |
+ error = ini_config_file_open(infile,
|
|
|
7990b5 |
+ 0,
|
|
|
7990b5 |
+ &file_ctx);
|
|
|
7990b5 |
+ if (error) {
|
|
|
7990b5 |
+ printf("Failed to open file for reading. Error %d.\n", error);
|
|
|
7990b5 |
+ return error;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ INIOUT(printf("Creating configuration object\n"));
|
|
|
7990b5 |
+ error = ini_config_create(&ini_config);
|
|
|
7990b5 |
+ if (error) {
|
|
|
7990b5 |
+ printf("Failed to create object. Error %d.\n", error);
|
|
|
7990b5 |
+ ini_config_file_destroy(file_ctx);
|
|
|
7990b5 |
+ return error;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+ INIOUT(printf("Parsing\n"));
|
|
|
7990b5 |
+ error = ini_config_parse(file_ctx,
|
|
|
7990b5 |
+ INI_STOP_ON_NONE,
|
|
|
7990b5 |
+ 0,
|
|
|
7990b5 |
+ 0,
|
|
|
7990b5 |
+ ini_config);
|
|
|
7990b5 |
+ if (error) {
|
|
|
7990b5 |
+ INIOUT(printf("Failed to parse configuration. "
|
|
|
7990b5 |
+ "Error %d.\n", error));
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ if (ini_config_error_count(ini_config)) {
|
|
|
7990b5 |
+ INIOUT(printf("Errors detected while parsing: %s\n",
|
|
|
7990b5 |
+ ini_config_get_filename(file_ctx)));
|
|
|
7990b5 |
+ ini_config_get_errors(ini_config, &error_list);
|
|
|
7990b5 |
+ INIOUT(ini_config_print_errors(stdout, error_list));
|
|
|
7990b5 |
+ ini_config_free_errors(error_list);
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+ ini_config_file_destroy(file_ctx);
|
|
|
7990b5 |
+ return error;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ INIOUT(col_debug_collection(ini_config->cfg, COL_TRAVERSE_DEFAULT));
|
|
|
7990b5 |
+ ini_config_file_destroy(file_ctx);
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ vo = NULL;
|
|
|
7990b5 |
+ error = ini_get_config_valueobj("domains/EXAMPLE.COM",
|
|
|
7990b5 |
+ "description",
|
|
|
7990b5 |
+ ini_config,
|
|
|
7990b5 |
+ INI_GET_FIRST_VALUE,
|
|
|
7990b5 |
+ &vo);
|
|
|
7990b5 |
+ if(error) {
|
|
|
7990b5 |
+ printf("Expected success but got error! %d\n",error);
|
|
|
7990b5 |
+ ini_config_destroy(ini_config);
|
|
|
7990b5 |
+ return error;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ /* Value should be found */
|
|
|
7990b5 |
+ if (vo == NULL) {
|
|
|
7990b5 |
+ printf("Expected success but got NULL.\n");
|
|
|
7990b5 |
+ ini_config_destroy(ini_config);
|
|
|
7990b5 |
+ return -1;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ value = ini_get_const_string_config_value(vo, NULL);
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ if (value == NULL) {
|
|
|
7990b5 |
+ printf("No value.\n");
|
|
|
7990b5 |
+ ini_config_destroy(ini_config);
|
|
|
7990b5 |
+ return -1;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ if(value[strlen(value) - 1] == ' ') {
|
|
|
7990b5 |
+ printf("Trailing space is not trimmed.\n");
|
|
|
7990b5 |
+ ini_config_destroy(ini_config);
|
|
|
7990b5 |
+ return -1;
|
|
|
7990b5 |
+ }
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ INIOUT(printf("[%s]\n", value));
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ ini_config_destroy(ini_config);
|
|
|
7990b5 |
+
|
|
|
7990b5 |
+ INIOUT(printf("\n<==== TRIM TEST END =====>\n\n"));
|
|
|
7990b5 |
+ return EOK;
|
|
|
7990b5 |
+}
|
|
|
7990b5 |
/* Main function of the unit test */
|
|
|
7990b5 |
int main(int argc, char *argv[])
|
|
|
7990b5 |
{
|
|
|
7990b5 |
@@ -2663,6 +2762,7 @@ int main(int argc, char *argv[])
|
|
|
7990b5 |
reload_test,
|
|
|
7990b5 |
get_test,
|
|
|
7990b5 |
space_test,
|
|
|
7990b5 |
+ trim_test,
|
|
|
7990b5 |
NULL };
|
|
|
7990b5 |
test_fn t;
|
|
|
7990b5 |
int i = 0;
|
|
|
7990b5 |
--
|
|
|
7990b5 |
1.8.3.1
|
|
|
7990b5 |
|