mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-17 20:42:24 +02:00
Added a tests of a string with a double quote in it
This commit is contained in:
@ -30,6 +30,13 @@ namespace JsonGeneratorTests
|
||||
AssertJsonIs("[\"hello\"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(AddOneStringContainingDoubleQuote)
|
||||
{
|
||||
arr.add("\"");
|
||||
|
||||
AssertJsonIs("[\"\\\"\"]");
|
||||
}
|
||||
|
||||
TEST_METHOD(AddTwoStrings)
|
||||
{
|
||||
arr.add("hello");
|
||||
|
@ -6,7 +6,7 @@ void JsonObjectBase::writeObjectTo(ObjectContainer& obj, StringBuilder& sb)
|
||||
{
|
||||
case JSON_STRING:
|
||||
if (obj.value.string)
|
||||
sb.append("\"%s\"", obj.value.string);
|
||||
sb.appendEscaped(obj.value.string);
|
||||
else
|
||||
sb.append("null");
|
||||
break;
|
||||
|
@ -12,3 +12,22 @@ void StringBuilder::append(const char* format, ...)
|
||||
|
||||
length += strlen(tail);
|
||||
}
|
||||
|
||||
void StringBuilder::appendEscaped(const char* s)
|
||||
{
|
||||
if (length > capacity - 3) return;
|
||||
|
||||
buffer[length++] = '"';
|
||||
|
||||
while (*s && length<capacity-2)
|
||||
{
|
||||
if (*s == '"')
|
||||
buffer[length++] = '\\';
|
||||
|
||||
buffer[length++] = *s;
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
buffer[length++] = '"';
|
||||
}
|
@ -18,6 +18,7 @@ public:
|
||||
}
|
||||
|
||||
void append(const char* format, ...);
|
||||
void appendEscaped(const char* s);
|
||||
|
||||
private:
|
||||
char* buffer;
|
||||
|
Reference in New Issue
Block a user