diff --git a/test/src/unit-class_parser.cpp b/test/src/unit-class_parser.cpp index c356937fd2..08d4d6efe7 100644 --- a/test/src/unit-class_parser.cpp +++ b/test/src/unit-class_parser.cpp @@ -205,6 +205,18 @@ TEST_CASE("parser class") CHECK_THROWS_WITH(parser_helper("\"\x1d\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"'"); CHECK_THROWS_WITH(parser_helper("\"\x1e\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"'"); CHECK_THROWS_WITH(parser_helper("\"\x1f\""), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"'"); + + SECTION("additional test for null byte") + { + // The test above for the null byte is wrong, because passing + // a string to the parser only reads int until it encounters + // a null byte. This test inserts the null byte later on and + // uses an iterator range. + std::string s = "\"1\""; + s[1] = '\0'; + CHECK_THROWS_AS(json::parse(s.begin(), s.end()), json::parse_error&); + CHECK_THROWS_WITH(json::parse(s.begin(), s.end()), "[json.exception.parse_error.101] parse error at 2: syntax error - invalid string: control character must be escaped; last read: '\"'"); + } } SECTION("escaped") diff --git a/test/src/unit-unicode.cpp b/test/src/unit-unicode.cpp index 9aab0f3c29..b51a1579ed 100644 --- a/test/src/unit-unicode.cpp +++ b/test/src/unit-unicode.cpp @@ -924,6 +924,40 @@ TEST_CASE("Unicode", "[hide]") } } + SECTION("incorrect sequences") + { + SECTION("incorrect surrogate values") + { + CHECK_THROWS_AS(json::parse("\"\\uDC00\\uDC00\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uDC00\\uDC00\""), + "[json.exception.parse_error.101] parse error at 7: syntax error - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uDC00'"); + + CHECK_THROWS_AS(json::parse("\"\\uD7FF\\uDC00\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uD7FF\\uDC00\""), + "[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF; last read: '\"\\uD7FF\\uDC00'"); + + CHECK_THROWS_AS(json::parse("\"\\uD800]\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uD800]\""), + "[json.exception.parse_error.101] parse error at 8: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800]'"); + + CHECK_THROWS_AS(json::parse("\"\\uD800\\v\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uD800\\v\""), + "[json.exception.parse_error.101] parse error at 9: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\v'"); + + CHECK_THROWS_AS(json::parse("\"\\uD800\\u123\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uD800\\u123\""), + "[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: '\\u' must be followed by 4 hex digits; last read: '\"\\uD800\\u123\"'"); + + CHECK_THROWS_AS(json::parse("\"\\uD800\\uDBFF\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uD800\\uDBFF\""), + "[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uDBFF'"); + + CHECK_THROWS_AS(json::parse("\"\\uD800\\uE000\""), json::parse_error&); + CHECK_THROWS_WITH(json::parse("\"\\uD800\\uE000\""), + "[json.exception.parse_error.101] parse error at 13: syntax error - invalid string: surrogate U+DC00..U+DFFF must be followed by U+DC00..U+DFFF; last read: '\"\\uD800\\uE000'"); + } + } + #if 0 SECTION("incorrect sequences") {