From ee205971e94d34617a676efd330385d2740218b9 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Tue, 14 Oct 2014 21:35:47 +0200 Subject: [PATCH] Test what happens with just an opening bracket --- srcs/Internals/JsonParser.cpp | 6 ++++-- tests/JsonArray_Parser_Tests.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/srcs/Internals/JsonParser.cpp b/srcs/Internals/JsonParser.cpp index fa245373..ac8f102e 100644 --- a/srcs/Internals/JsonParser.cpp +++ b/srcs/Internals/JsonParser.cpp @@ -67,12 +67,14 @@ JsonNode* JsonParser::parseNode() JsonNode* JsonParser::parseArray() { - skipOneChar(); + skipOneChar(); // skip the '[' + skipSpaces(); JsonNode* node = _buffer->createNode(); node->setAsArray(_buffer); - skipSpaces(); + if (isEnd()) + return 0; if (isArrayStop()) return node; diff --git a/tests/JsonArray_Parser_Tests.cpp b/tests/JsonArray_Parser_Tests.cpp index 8f8ada61..78822743 100644 --- a/tests/JsonArray_Parser_Tests.cpp +++ b/tests/JsonArray_Parser_Tests.cpp @@ -16,6 +16,14 @@ TEST_F(JsonArray_Parser_Tests, EmptyArray) 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) { JsonArray array = json.parseArray(" []");