Test what happens with just an opening bracket

This commit is contained in:
Benoit Blanchon
2014-10-14 21:35:47 +02:00
parent ded6364e1d
commit ee205971e9
2 changed files with 12 additions and 2 deletions

View File

@ -67,12 +67,14 @@ JsonNode* JsonParser::parseNode()
JsonNode* JsonParser::parseArray() JsonNode* JsonParser::parseArray()
{ {
skipOneChar(); skipOneChar(); // skip the '['
skipSpaces();
JsonNode* node = _buffer->createNode(); JsonNode* node = _buffer->createNode();
node->setAsArray(_buffer); node->setAsArray(_buffer);
skipSpaces(); if (isEnd())
return 0;
if (isArrayStop()) if (isArrayStop())
return node; return node;

View File

@ -16,6 +16,14 @@ TEST_F(JsonArray_Parser_Tests, EmptyArray)
EXPECT_EQ(0, array.size()); EXPECT_EQ(0, array.size());
} }
TEST_F(JsonArray_Parser_Tests, ArrayWithNoEnd)
{
JsonArray array = json.parseArray("[");
EXPECT_FALSE(array.success());
EXPECT_EQ(0, array.size());
}
TEST_F(JsonArray_Parser_Tests, EmptyArrayWithLeadingSpaces) TEST_F(JsonArray_Parser_Tests, EmptyArrayWithLeadingSpaces)
{ {
JsonArray array = json.parseArray(" []"); JsonArray array = json.parseArray(" []");