diff --git a/src/Internals/JsonParser.cpp b/src/Internals/JsonParser.cpp index df064475..3849e02b 100644 --- a/src/Internals/JsonParser.cpp +++ b/src/Internals/JsonParser.cpp @@ -211,7 +211,12 @@ JsonNode* JsonParser::parseObject() for(;;) { - node->addChild(parseObjectKeyValue()); + JsonNode* keyValueNode = parseObjectKeyValue(); + + if (!keyValueNode) + return 0; + + node->addChild(keyValueNode); skipSpaces(); @@ -229,6 +234,9 @@ JsonNode* JsonParser::parseObjectKeyValue() { const char* key = QuotedString::extractFrom(_ptr, &_ptr); + if (!key) + return 0; + skipSpaces(); if (!isColon()) diff --git a/src/Internals/JsonWriter.cpp b/src/Internals/JsonWriter.cpp index 6df0a2a5..a4614019 100644 --- a/src/Internals/JsonWriter.cpp +++ b/src/Internals/JsonWriter.cpp @@ -10,7 +10,6 @@ void JsonWriter::writeString(char const* value) void JsonWriter::writeInteger(long value) { - _length += _sink->print(value); } @@ -21,5 +20,5 @@ void JsonWriter::writeBoolean(bool value) void JsonWriter::writeDouble(double value, int decimals) { - _length += _sink->print(value, decimals); + _length += _sink->print(value, decimals); } \ No newline at end of file diff --git a/src/Internals/EscapedString.cpp b/src/Internals/QuotedString.cpp similarity index 98% rename from src/Internals/EscapedString.cpp rename to src/Internals/QuotedString.cpp index 6807130c..9b361090 100644 --- a/src/Internals/EscapedString.cpp +++ b/src/Internals/QuotedString.cpp @@ -91,7 +91,6 @@ char* QuotedString::extractFrom(char* input, char** endPtr) if (c == 0) { // premature ending - *endPtr = 0; return 0; } @@ -108,7 +107,7 @@ char* QuotedString::extractFrom(char* input, char** endPtr) } *writePtr++ = c; - } + } // end the string here *writePtr = 0; diff --git a/test/JsonParser_Object_Tests.cpp b/test/JsonParser_Object_Tests.cpp index 6538da37..a9df0ed0 100644 --- a/test/JsonParser_Object_Tests.cpp +++ b/test/JsonParser_Object_Tests.cpp @@ -54,6 +54,21 @@ TEST_F(JsonParser_Object_Test, MissingClosingBrace) sizeMustBe(0); } +TEST_F(JsonParser_Object_Test, MissingColonAndValue) +{ + whenInputIs("{\"key\"}"); + parseMustFail(); + sizeMustBe(0); +} + +TEST_F(JsonParser_Object_Test, MissingQuotesAndColonAndValue) +{ + whenInputIs("{key}"); + parseMustFail(); + sizeMustBe(0); +} + + TEST_F(JsonParser_Object_Test, OneStringNoSpace) { whenInputIs("{\"key\":\"value\"}");