INI: Strip trailing whitespace
This commit is contained in:
parent
b0a3d7e6ab
commit
700b77dbc7
166
0002-Trim-trailing-spaces.patch
Normal file
166
0002-Trim-trailing-spaces.patch
Normal file
@ -0,0 +1,166 @@
|
||||
From 8390d1d432330e143832734d5799528013e79178 Mon Sep 17 00:00:00 2001
|
||||
From: Dmitri Pal <dpal@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
|
||||
|
@ -1,6 +1,6 @@
|
||||
Name: ding-libs
|
||||
Version: 0.3.0.1
|
||||
Release: 18%{?dist}
|
||||
Release: 19%{?dist}
|
||||
Summary: "Ding is not GLib" assorted utility libraries
|
||||
Group: Development/Libraries
|
||||
License: LGPLv3+
|
||||
@ -20,6 +20,7 @@ BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
|
||||
|
||||
### Patches ###
|
||||
Patch0001: 0001-INI-Bump-version-info.patch
|
||||
Patch0002: 0002-Trim-trailing-spaces.patch
|
||||
|
||||
### Dependencies ###
|
||||
# ding-libs is a meta-package that will pull in all of its own
|
||||
@ -322,6 +323,7 @@ structure
|
||||
%prep
|
||||
%setup -q
|
||||
%patch0001 -p1 -b .version
|
||||
%patch0002 -p1 -b .whitespace
|
||||
|
||||
%build
|
||||
autoreconf -ivf
|
||||
@ -356,6 +358,9 @@ rm -f */doc/html/installdox
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
%changelog
|
||||
* Fri Sep 27 2013 Jakub Hrozek <jhrozek@redhat.com> - 0.3.0.1-19
|
||||
- Apply a patch by Dmitri Pal to strip trailing whitespace
|
||||
|
||||
* Sat Aug 03 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.3.0.1-18
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user