[ding-libs/f19] INI: Strip trailing whitespace

Jakub Hrozek jhrozek at fedoraproject.org
Fri Sep 27 09:39:47 UTC 2013


commit c63b8f04ae8966de12fa3d413a0e0e064ee1d0b0
Author: Jakub Hrozek <jhrozek at redhat.com>
Date:   Fri Sep 27 11:19:18 2013 +0200

    INI: Strip trailing whitespace

 0004-Trim-trailing-spaces.patch |  166 +++++++++++++++++++++++++++++++++++++++
 ding-libs.spec                  |   11 ++-
 2 files changed, 174 insertions(+), 3 deletions(-)
---
diff --git a/0004-Trim-trailing-spaces.patch b/0004-Trim-trailing-spaces.patch
new file mode 100644
index 0000000..b8b501e
--- /dev/null
+++ b/0004-Trim-trailing-spaces.patch
@@ -0,0 +1,166 @@
+From 8390d1d432330e143832734d5799528013e79178 Mon Sep 17 00:00:00 2001
+From: Dmitri Pal <dpal at redhat.com>
+Date: Mon, 23 Sep 2013 16:03:30 -0400
+Subject: [PATCH] Trim trailing spaces
+
+This patch addressed issue https://fedorahosted.org/sssd/ticket/2095
+The new parser in fact stopped trimming trailing spaces.
+This is now corrected.
+---
+ ini/ini.d/real.conf |   2 +-
+ ini/ini_parse.c     |   7 ++++
+ ini/ini_parse_ut.c  | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 108 insertions(+), 1 deletion(-)
+
+diff --git a/ini/ini.d/real.conf b/ini/ini.d/real.conf
+index 32bc9dae0c40ce46dc4c375963b5d0cf2a05e17b..1e155b820061001695d85edfeca1819e799e2a4b 100644
+--- a/ini/ini.d/real.conf
++++ b/ini/ini.d/real.conf
+@@ -40,7 +40,7 @@ legacy = FALSE
+ enumerate = 3
+ 
+ [domains/EXAMPLE.COM]
+-description = Example domain served by IPA
++description = Example domain served by IPA 
+ provider = ipa
+ server = ipaserver1.example.com
+ server = ipabackupserver.example.com
+diff --git a/ini/ini_parse.c b/ini/ini_parse.c
+index 60ef1169986f2ea27596931ebf16fab166c71937..9a1c0ec63013adb986b627c977c9759c1d5a210e 100644
+--- a/ini/ini_parse.c
++++ b/ini/ini_parse.c
+@@ -968,6 +968,13 @@ static int handle_kvp(struct parser_obj *po, uint32_t *action)
+         full_len--;
+     }
+ 
++    /* Trucate trailing spaces */
++    /* Make sure not to step before the beginning */
++    while (full_len && isspace(str[full_len - 1])) {
++        str[full_len - 1] = '\0';
++        full_len--;
++    }
++
+     /* Check if we have the key */
+     if (*(str) == '=') {
+         po->last_error = ERR_NOKEY;
+diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c
+index 32c59e7a3a36a5b719620ae42cf070154d4eb416..2655d7e8e11a391db324a9c022004f7cbbeb092e 100644
+--- a/ini/ini_parse_ut.c
++++ b/ini/ini_parse_ut.c
+@@ -2650,6 +2650,105 @@ int space_test(void)
+     return EOK;
+ }
+ 
++
++int trim_test(void)
++{
++    int error;
++    struct ini_cfgfile *file_ctx = NULL;
++    struct ini_cfgobj *ini_config = NULL;
++    char **error_list = NULL;
++    char infile[PATH_MAX];
++    char *srcdir = NULL;
++    const char *value;
++    struct value_obj *vo = NULL;
++
++    INIOUT(printf("\n\n<==== TRIM TEST START =====>\n"));
++
++    srcdir = getenv("srcdir");
++    snprintf(infile, PATH_MAX, "%s/ini/ini.d/real.conf",
++             (srcdir == NULL) ? "." : srcdir);
++
++
++    INIOUT(printf("Reading file %s\n", infile));
++    error = ini_config_file_open(infile,
++                                 0,
++                                 &file_ctx);
++    if (error) {
++        printf("Failed to open file for reading. Error %d.\n",  error);
++        return error;
++    }
++
++    INIOUT(printf("Creating configuration object\n"));
++    error = ini_config_create(&ini_config);
++    if (error) {
++        printf("Failed to create object. Error %d.\n", error);
++        ini_config_file_destroy(file_ctx);
++        return error;
++    }
++    INIOUT(printf("Parsing\n"));
++    error = ini_config_parse(file_ctx,
++                             INI_STOP_ON_NONE,
++                             0,
++                             0,
++                             ini_config);
++    if (error) {
++        INIOUT(printf("Failed to parse configuration. "
++                      "Error %d.\n", error));
++
++        if (ini_config_error_count(ini_config)) {
++            INIOUT(printf("Errors detected while parsing: %s\n",
++                   ini_config_get_filename(file_ctx)));
++            ini_config_get_errors(ini_config, &error_list);
++            INIOUT(ini_config_print_errors(stdout, error_list));
++            ini_config_free_errors(error_list);
++        }
++        ini_config_file_destroy(file_ctx);
++        return error;
++    }
++
++    INIOUT(col_debug_collection(ini_config->cfg, COL_TRAVERSE_DEFAULT));
++    ini_config_file_destroy(file_ctx);
++
++    vo = NULL;
++    error = ini_get_config_valueobj("domains/EXAMPLE.COM",
++                                    "description",
++                                    ini_config,
++                                    INI_GET_FIRST_VALUE,
++                                    &vo);
++    if(error) {
++        printf("Expected success but got error! %d\n",error);
++        ini_config_destroy(ini_config);
++        return error;
++    }
++
++    /* Value should be found */
++    if (vo == NULL) {
++        printf("Expected success but got NULL.\n");
++        ini_config_destroy(ini_config);
++        return -1;
++    }
++
++    value = ini_get_const_string_config_value(vo, NULL);
++
++    if (value == NULL) {
++        printf("No value.\n");
++        ini_config_destroy(ini_config);
++        return -1;
++    }
++
++    if(value[strlen(value) - 1] == ' ') {
++        printf("Trailing space is not trimmed.\n");
++        ini_config_destroy(ini_config);
++        return -1;
++    }
++
++    INIOUT(printf("[%s]\n", value));
++
++    ini_config_destroy(ini_config);
++
++    INIOUT(printf("\n<==== TRIM TEST END =====>\n\n"));
++    return EOK;
++}
+ /* Main function of the unit test */
+ int main(int argc, char *argv[])
+ {
+@@ -2663,6 +2762,7 @@ int main(int argc, char *argv[])
+                         reload_test,
+                         get_test,
+                         space_test,
++                        trim_test,
+                         NULL };
+     test_fn t;
+     int i = 0;
+-- 
+1.8.3.1
+
diff --git a/ding-libs.spec b/ding-libs.spec
index 184f8b6..cfde630 100644
--- a/ding-libs.spec
+++ b/ding-libs.spec
@@ -1,6 +1,6 @@
 Name: ding-libs
 Version: 0.3.0.1
-Release: 18%{?dist}
+Release: 20%{?dist}
 Summary: "Ding is not GLib" assorted utility libraries
 Group: Development/Libraries
 License: LGPLv3+
@@ -22,6 +22,7 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
 Patch0001:  0001-INI-Bump-version-info.patch
 Patch0002:  0002-DOXY-Don-t-generate-timestamp.patch
 Patch0003:  0003-rpm-Include-the-right-filename-of-libini_config.patch
+Patch0004:  0004-Trim-trailing-spaces.patch
 
 ### Dependencies ###
 # ding-libs is a meta-package that will pull in all of its own
@@ -324,8 +325,9 @@ structure
 %prep
 %setup -q
 %patch0001 -p1 -b .version
-%patch0002 -p1 -b .version
-%patch0003 -p1 -b .version
+%patch0002 -p1 -b .timestamp
+%patch0003 -p1 -b .rpmbuild
+%patch0004 -p1 -b .whitespace
 
 %build
 autoreconf -ivf
@@ -360,6 +362,9 @@ rm -f */doc/html/installdox
 rm -rf $RPM_BUILD_ROOT
 
 %changelog
+* Fri Sep 27 2013 Jakub Hrozek <jhrozek at redhat.com> - 0.3.0.1-20
+- Apply a patch by Dmitri Pal to strip trailing whitespace
+
 * Tue Jul 16 2013 Ondrej Kos <okos at redhat.com> - 0.3.0.1-18
 - Apply patch to stop generating doxygen timestamps
 - Apply patch to include correct libini_config file


More information about the scm-commits mailing list