]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Escape line breaks in json
authorJosé Iván López González <jlopez@suse.com>
Tue, 5 Nov 2019 16:01:30 +0000 (16:01 +0000)
committerJosé Iván López González <jlopez@suse.com>
Tue, 5 Nov 2019 16:01:30 +0000 (16:01 +0000)
client/utils/JsonFormatter.cc
testsuite/json-formatter.cc

index 4fd815053ab7526d9b8a7cb2a44d5d54818a7370..4da11f7af14486267a03d82dbf12a129145080cc 100644 (file)
@@ -48,6 +48,7 @@ namespace snapper
 
                boost::algorithm::replace_all(fixed_value, "\\", "\\\\");
                boost::algorithm::replace_all(fixed_value, "\"", "\\\"");
+               boost::algorithm::replace_all(fixed_value, "\n", "");
 
                return fixed_value;
            }
index 74801b5fa7393f508ad9923683ffac9f56b6f886..6a6193be3bfd0244c02ae8dc49c8b09cf2dafe11 100644 (file)
@@ -17,6 +17,7 @@ BOOST_AUTO_TEST_CASE(test1_escape_values)
        { "key1", "value1" },
        { "key2", "value\"2" },
        { "key3", "value\\3" },
+       { "key3", "value\n3" },
        { "key4", "\"value4\"" }
     };
 
@@ -25,6 +26,7 @@ BOOST_AUTO_TEST_CASE(test1_escape_values)
        "  \"key1\": \"value1\",\n"
        "  \"key2\": \"value\\\"2\",\n"
        "  \"key3\": \"value\\\\3\",\n"
+       "  \"key3\": \"value3\",\n"
        "  \"key4\": \"\\\"value4\\\"\"\n"
        "}";
 
@@ -37,13 +39,13 @@ BOOST_AUTO_TEST_CASE(test1_escape_values)
 BOOST_AUTO_TEST_CASE(test2_skip_format)
 {
     snapper::cli::JsonFormatter::Data data = {
-       { "key1", "value1" },
+       { "key1", "true" },
        { "key2", "value2" }
     };
 
     string expected_result =
        "{\n"
-       "  \"key1\": value1,\n"
+       "  \"key1\": true,\n"
        "  \"key2\": \"value2\"\n"
        "}";