Commit 2c936393 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

Merge branch 'trac1072'

parents 3383b560 ec45081d
......@@ -447,7 +447,9 @@ from_stringstream_map(std::istream &in, const std::string& file, int& line,
ElementPtr map = Element::createMap();
skip_chars(in, " \t\n", line, pos);
char c = in.peek();
if (c == '}') {
if (c == EOF) {
throwJSONError(std::string("Unterminated map, <string> or } expected"), file, line, pos);
} else if (c == '}') {
// empty map, skip closing curly
c = in.get();
} else {
......
......@@ -396,9 +396,24 @@ TEST(Element, to_and_from_wire) {
EXPECT_EQ("1", Element::fromWire(ss, 1)->str());
// Some malformed JSON input
EXPECT_THROW(Element::fromJSON("{ "), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\" "), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\": "), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\": \"b\""), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\": {"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\": {}"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\": []"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\": [ }"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{\":"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("]"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("[ 1, 2, }"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("[ 1, 2, {}"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("[ 1, 2, { ]"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("[ "), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{{}}"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{[]}"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("{ \"a\", \"b\" }"), isc::data::JSONError);
EXPECT_THROW(Element::fromJSON("[ \"a\": \"b\" ]"), isc::data::JSONError);
}
ConstElementPtr
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment