Fix lax parsing of true, false, and null (fixes #1781)

This commit is contained in:
Benoit Blanchon
2022-08-04 12:39:34 +02:00
parent 5705247e5f
commit 1d21027e2a
4 changed files with 116 additions and 34 deletions

View File

@ -71,6 +71,15 @@ TEST_CASE("Filtering") {
"{\"example\":null}",
JSON_OBJECT_SIZE(1) + 8
},
{
// Member is a number, but filter wants an array
"{\"example\":42}",
"{\"example\":[true]}",
10,
DeserializationError::Ok,
"{\"example\":null}",
JSON_OBJECT_SIZE(1) + 8
},
{
// Input is an array, but filter wants an object
"[\"hello\",\"world\"]",
@ -117,7 +126,7 @@ TEST_CASE("Filtering") {
JSON_OBJECT_SIZE(1) + 8
},
{
// can skip a boolean
// skip false
"{\"a_bool\":false,example:42}",
"{\"example\":true}",
10,
@ -125,6 +134,24 @@ TEST_CASE("Filtering") {
"{\"example\":42}",
JSON_OBJECT_SIZE(1) + 8
},
{
// skip true
"{\"a_bool\":true,example:42}",
"{\"example\":true}",
10,
DeserializationError::Ok,
"{\"example\":42}",
JSON_OBJECT_SIZE(1) + 8
},
{
// skip null
"{\"a_bool\":null,example:42}",
"{\"example\":true}",
10,
DeserializationError::Ok,
"{\"example\":42}",
JSON_OBJECT_SIZE(1) + 8
},
{
// can skip a double-quoted string
"{\"a_double_quoted_string\":\"hello\",example:42}",
@ -618,7 +645,7 @@ TEST_CASE("Filtering") {
0
},
{
// incomplete after after key of a skipped object
// incomplete comment after key of a skipped object
"{\"example\"/*:2}",
"false",
10,
@ -636,7 +663,7 @@ TEST_CASE("Filtering") {
0
},
{
// incomplete after after value of a skipped object
// incomplete comment after value of a skipped object
"{\"example\":2/*}",
"false",
10,
@ -644,6 +671,15 @@ TEST_CASE("Filtering") {
"null",
0
},
{
// incomplete comment after comma in skipped object
"{\"example\":2,/*}",
"false",
10,
DeserializationError::IncompleteInput,
"null",
0
},
}; // clang-format on
for (size_t i = 0; i < sizeof(testCases) / sizeof(testCases[0]); i++) {

View File

@ -9,7 +9,8 @@
TEST_CASE("Invalid JSON input") {
const char* testCases[] = {"'\\u'", "'\\u000g'", "'\\u000'", "'\\u000G'",
"'\\u000/'", "\\x1234", "6a9", "1,",
"2]", "3}"};
"nulL", "tru3", "fals3", "2]",
"3}"};
const size_t testCount = sizeof(testCases) / sizeof(testCases[0]);
DynamicJsonDocument doc(4096);
@ -23,9 +24,6 @@ TEST_CASE("Invalid JSON input") {
TEST_CASE("Invalid JSON input that should pass") {
const char* testCases[] = {
"nulL",
"tru3",
"fals3",
"'\\ud83d'", // leading surrogate without a trailing surrogate
"'\\udda4'", // trailing surrogate without a leading surrogate
"'\\ud83d\\ud83d'", // two leading surrogates