changeset 521:77495c646208

Fix parsing and writing of strings with simple escape sequences in config files.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 26 Dec 2019 13:34:19 +0200
parents 8b36f2566cf9
children b4884e59fdd3
files cfg.test01 tests.c th_config.c
diffstat 3 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cfg.test01	Thu Dec 26 13:17:32 2019 +0200
+++ b/cfg.test01	Thu Dec 26 13:34:19 2019 +0200
@@ -13,10 +13,10 @@
     boolval = no
 
     # A string list
-    string_list = "zoo",
+    string_list = "\zoo",
 
    "foo",
-"bar"
+"b\"ar"
 }
 
 another_sect = {
--- a/tests.c	Thu Dec 26 13:17:32 2019 +0200
+++ b/tests.c	Thu Dec 26 13:34:19 2019 +0200
@@ -372,7 +372,7 @@
 
 static const char *test_strings[] =
 {
-    "zoo", "foo", "bar",
+    "zoo", "foo", "b\"ar",
 };
 
 static const int ntest_strings = sizeof(test_strings) / sizeof(test_strings[0]);
--- a/th_config.c	Thu Dec 26 13:17:32 2019 +0200
+++ b/th_config.c	Thu Dec 26 13:34:19 2019 +0200
@@ -587,6 +587,7 @@
                         SET_MAX_BUF);
                     ctx.parseMode = PM_ERROR;
                 }
+                isEscaped = FALSE;
             }
 
             ctx.ch = -1;
@@ -897,9 +898,9 @@
                 for (; node != NULL; node = node->next)
                 if (node->data != NULL)
                 {
-                    if (!th_print_indent(fh, nesting, "\"%s\"%s\n",
-                        (char *) node->data,
-                        --n > 0 ? "," : ""))
+                    if (!th_print_indent(fh, nesting, "\"") ||
+                        !th_cfg_write_string_escaped(fh, (char *) node->data, '"') ||
+                        thfprintf(fh, "\"%s\n", (--n > 0) ? "," : "") < 0)
                         return THERR_FWRITE;
                 }