More test on object parsing

This commit is contained in:
Benoit Blanchon
2014-10-22 10:55:36 +02:00
parent c82e6d747b
commit 316d036785
4 changed files with 26 additions and 5 deletions

View File

@ -211,7 +211,12 @@ JsonNode* JsonParser::parseObject()
for(;;) for(;;)
{ {
node->addChild(parseObjectKeyValue()); JsonNode* keyValueNode = parseObjectKeyValue();
if (!keyValueNode)
return 0;
node->addChild(keyValueNode);
skipSpaces(); skipSpaces();
@ -229,6 +234,9 @@ JsonNode* JsonParser::parseObjectKeyValue()
{ {
const char* key = QuotedString::extractFrom(_ptr, &_ptr); const char* key = QuotedString::extractFrom(_ptr, &_ptr);
if (!key)
return 0;
skipSpaces(); skipSpaces();
if (!isColon()) if (!isColon())

View File

@ -10,7 +10,6 @@ void JsonWriter::writeString(char const* value)
void JsonWriter::writeInteger(long value) void JsonWriter::writeInteger(long value)
{ {
_length += _sink->print(value); _length += _sink->print(value);
} }
@ -21,5 +20,5 @@ void JsonWriter::writeBoolean(bool value)
void JsonWriter::writeDouble(double value, int decimals) void JsonWriter::writeDouble(double value, int decimals)
{ {
_length += _sink->print(value, decimals); _length += _sink->print(value, decimals);
} }

View File

@ -91,7 +91,6 @@ char* QuotedString::extractFrom(char* input, char** endPtr)
if (c == 0) if (c == 0)
{ {
// premature ending // premature ending
*endPtr = 0;
return 0; return 0;
} }
@ -108,7 +107,7 @@ char* QuotedString::extractFrom(char* input, char** endPtr)
} }
*writePtr++ = c; *writePtr++ = c;
} }
// end the string here // end the string here
*writePtr = 0; *writePtr = 0;

View File

@ -54,6 +54,21 @@ TEST_F(JsonParser_Object_Test, MissingClosingBrace)
sizeMustBe(0); 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) TEST_F(JsonParser_Object_Test, OneStringNoSpace)
{ {
whenInputIs("{\"key\":\"value\"}"); whenInputIs("{\"key\":\"value\"}");