diff --git a/JsonGeneratorTests/JsonArrayTests.cpp b/JsonGeneratorTests/JsonArrayTests.cpp index 6d1c9cbf..0199939e 100644 --- a/JsonGeneratorTests/JsonArrayTests.cpp +++ b/JsonGeneratorTests/JsonArrayTests.cpp @@ -37,6 +37,13 @@ namespace JsonGeneratorTests AssertJsonIs("[\"\\\"\"]"); } + TEST_METHOD(AddOneStringContainingBackslash) + { + arr.add("\\"); + + AssertJsonIs("[\"\\\\\"]"); + } + TEST_METHOD(AddTwoStrings) { arr.add("hello"); diff --git a/JsonGeneratorTests/StringBuilder.cpp b/JsonGeneratorTests/StringBuilder.cpp index 5da8a7ee..a888e097 100644 --- a/JsonGeneratorTests/StringBuilder.cpp +++ b/JsonGeneratorTests/StringBuilder.cpp @@ -5,7 +5,7 @@ void StringBuilder::append(const char* s) { char* tail = buffer + length; - strcpy(tail, s); + strncpy(tail, s, capacity - length); length += strlen(tail); } @@ -16,17 +16,35 @@ void StringBuilder::appendEscaped(const char* s) buffer[length++] = '"'; - while (*s && length