2
1
mirror of https://github.com/qpdf/qpdf.git synced 2025-01-23 15:18:33 +00:00

In JSONParser::handleToken move validation for ls_colon etc into switch statement

This commit is contained in:
m-holger 2023-01-26 14:10:48 +00:00
parent 6f94a3a89a
commit 4dba3c95dd

View File

@ -1150,10 +1150,44 @@ JSONParser::handleToken()
break; break;
case ls_colon: case ls_colon:
if (parser_state != ps_dict_after_key) {
QTC::TC("libtests", "JSON parse unexpected :");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected colon");
}
break;
case ls_comma: case ls_comma:
if (!((parser_state == ps_dict_after_item) ||
(parser_state == ps_array_after_item))) {
QTC::TC("libtests", "JSON parse unexpected ,");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected comma");
}
break;
case ls_end_array: case ls_end_array:
if (!((parser_state == ps_array_begin) ||
(parser_state == ps_array_after_item)))
{
QTC::TC("libtests", "JSON parse unexpected ]");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected array end delimiter");
}
break;
case ls_end_dict: case ls_end_dict:
// continue if (!((parser_state == ps_dict_begin) ||
(parser_state == ps_dict_after_item))) {
QTC::TC("libtests", "JSON parse unexpected }");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected dictionary end delimiter");
}
break; break;
case ls_number: case ls_number:
@ -1235,41 +1269,6 @@ JSONParser::handleToken()
break; break;
// okay // okay
} }
} else if (lex_state == ls_end_dict) {
if (!((parser_state == ps_dict_begin) ||
(parser_state == ps_dict_after_item)))
{
QTC::TC("libtests", "JSON parse unexpected }");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected dictionary end delimiter");
}
} else if (lex_state == ls_end_array) {
if (!((parser_state == ps_array_begin) ||
(parser_state == ps_array_after_item)))
{
QTC::TC("libtests", "JSON parse unexpected ]");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected array end delimiter");
}
} else if (lex_state == ls_colon) {
if (parser_state != ps_dict_after_key) {
QTC::TC("libtests", "JSON parse unexpected :");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected colon");
}
} else if (lex_state == ls_comma) {
if (!((parser_state == ps_dict_after_item) ||
(parser_state == ps_array_after_item))) {
QTC::TC("libtests", "JSON parse unexpected ,");
throw std::runtime_error(
"JSON: offset " + std::to_string(offset) +
": unexpected comma");
}
} }
// Now we know we have a delimiter or item that is allowed. Do // Now we know we have a delimiter or item that is allowed. Do