From dd3f77b0a5969862b633e16deea35a7896815de6 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 2 Jul 2020 09:44:18 -0400 Subject: [PATCH] trim trailing spaces from config values closes #843 Change-Id: Icf59d5474edde8265f48b179488c11a367b57b8b --- lib/auxlib.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/auxlib.c b/lib/auxlib.c index 6514f5e71..3cb015a15 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -256,7 +256,8 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char g_option_context_parse_strv(c, &saved_argv, &er); // finally go through our list again to look for strings that were - // overwritten, and free the old values + // overwritten, and free the old values. + // this is also a good opportunity to trim off stray spaces. for (GOptionEntry *e = entries_copy; e->long_name; e++) { switch (e->arg) { case G_OPTION_ARG_STRING: @@ -264,6 +265,11 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char char **s = e->arg_data; if (*s != e->description) g_free((void *) e->description); + if (*s) { + size_t len = strlen(*s); + while (len && (*s)[len-1] == ' ') + (*s)[--len] = '\0'; + } break; } @@ -271,6 +277,14 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char char ***s = e->arg_data; if (*s != (void *) e->description) g_strfreev((void *) e->description); + if (*s) { + for (int i = 0; (*s)[i]; i++) { + char *ss = (*s)[i]; + size_t len = strlen(ss); + while (len && ss[len-1] == ' ') + ss[--len] = '\0'; + } + } break; }