@@ -19,7 +19,8 @@ TEST_CLASS(JsonFormatterTests)
1919 {
2020 { L" InstanceId" , L" a1b2c3" },
2121 { L" InstallationName" , L" test" },
22- { L" InstallDate" , L" 2017-02-23T01:22:35Z" }
22+ { L" InstallDate" , L" 2017-02-23T01:22:35Z" },
23+ { L" Description" , L" This description contains \" quotes\" ." },
2324 };
2425
2526 JsonFormatter sut;
@@ -30,7 +31,8 @@ TEST_CLASS(JsonFormatterTests)
3031 L" {\n "
3132 L" \" instanceId\" : \" a1b2c3\" ,\n "
3233 L" \" installDate\" : \" 2017-02-23T01:22:35Z\" ,\n "
33- L" \" installationName\" : \" test\"\n "
34+ L" \" installationName\" : \" test\" ,\n "
35+ L" \" description\" : \" This description contains \\\" quotes\\\" .\"\n "
3436 L" }\n "
3537 L" ]\n " ;
3638
@@ -506,4 +508,27 @@ TEST_CLASS(JsonFormatterTests)
506508
507509 Assert::AreEqual (expected, console);
508510 }
511+
512+ TEST_METHOD (Escape)
513+ {
514+ vector<tuple<wstring, wstring>> data =
515+ {
516+ { L" value" , L" value" },
517+ { L" C:\\ ShouldNotExist" , L" C:\\\\ ShouldNotExist" },
518+ { L" C:\\ ShouldNotExist\\ Sub" , L" C:\\\\ ShouldNotExist\\\\ Sub" },
519+ { L" \\\\ ShouldNotExist" , L" \\\\\\\\ ShouldNotExist" },
520+ { L" \" value\" " , L" \\\" value\\\" " },
521+ { L" \" C:\\ ShouldNotExist\" " , L" \\\" C:\\\\ ShouldNotExist\\\" " },
522+ };
523+
524+ for (const auto & item : data)
525+ {
526+ wstring source, expected;
527+
528+ tie (source, expected) = item;
529+ auto actual = JsonFormatter::Escape (source);
530+
531+ Assert::AreEqual (expected.c_str (), actual.c_str ());
532+ }
533+ }
509534};
0 commit comments