]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Add control char escapes 494/head
authorJosé Iván López <joseivanlopez@gmail.com>
Wed, 6 Nov 2019 08:42:06 +0000 (08:42 +0000)
committerJosé Iván López González <jlopez@suse.com>
Wed, 6 Nov 2019 08:47:04 +0000 (08:47 +0000)
Co-Authored-By: Martin Vidner <martin@vidner.net>
client/utils/JsonFormatter.cc
testsuite/json-formatter.cc

index 4da11f7af14486267a03d82dbf12a129145080cc..ec2f7c667d2e9aa1bd8f840e002ee74cef1db518 100644 (file)
@@ -48,7 +48,11 @@ namespace snapper
 
                boost::algorithm::replace_all(fixed_value, "\\", "\\\\");
                boost::algorithm::replace_all(fixed_value, "\"", "\\\"");
-               boost::algorithm::replace_all(fixed_value, "\n", "");
+               boost::algorithm::replace_all(fixed_value, "\b", "\\b");
+               boost::algorithm::replace_all(fixed_value, "\f", "\\f");
+               boost::algorithm::replace_all(fixed_value, "\n", "\\n");
+               boost::algorithm::replace_all(fixed_value, "\r", "\\r");
+               boost::algorithm::replace_all(fixed_value, "\t", "\\t");
 
                return fixed_value;
            }
@@ -125,4 +129,4 @@ namespace snapper
        }
 
     }
-}
\ No newline at end of file
+}
index 6a6193be3bfd0244c02ae8dc49c8b09cf2dafe11..541a85ad9a925fae68c8bf26f94349edf42d6535 100644 (file)
@@ -17,8 +17,12 @@ BOOST_AUTO_TEST_CASE(test1_escape_values)
        { "key1", "value1" },
        { "key2", "value\"2" },
        { "key3", "value\\3" },
-       { "key3", "value\n3" },
-       { "key4", "\"value4\"" }
+       { "key3", "value\b4" },
+       { "key3", "value\f5" },
+       { "key3", "value\n6" },
+       { "key3", "value\r7" },
+       { "key3", "value\t8" },
+       { "key4", "\"value9\"" }
     };
 
     string expected_result =
@@ -26,8 +30,12 @@ BOOST_AUTO_TEST_CASE(test1_escape_values)
        "  \"key1\": \"value1\",\n"
        "  \"key2\": \"value\\\"2\",\n"
        "  \"key3\": \"value\\\\3\",\n"
-       "  \"key3\": \"value3\",\n"
-       "  \"key4\": \"\\\"value4\\\"\"\n"
+       "  \"key3\": \"value\\b4\",\n"
+       "  \"key3\": \"value\\f5\",\n"
+       "  \"key3\": \"value\\n6\",\n"
+       "  \"key3\": \"value\\r7\",\n"
+       "  \"key3\": \"value\\t8\",\n"
+       "  \"key4\": \"\\\"value9\\\"\"\n"
        "}";
 
     snapper::cli::JsonFormatter formatter(data);