summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-01-26 15:10:48 +0100
committerm-holger <m-holger@kubitscheck.org>2023-02-04 14:53:22 +0100
commit4dba3c95dd9cc721957f8138fe19ab2872328f27 (patch)
treecc5cfa62a49743be4e8199b2c22190b8e65eebae
parent6f94a3a89ab4dc7be0c053c53a94868b6c9a747c (diff)
downloadqpdf-4dba3c95dd9cc721957f8138fe19ab2872328f27.tar.zst
In JSONParser::handleToken move validation for ls_colon etc into switch statement
-rw-r--r--libqpdf/JSON.cc71
1 files changed, 35 insertions, 36 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index ef652a86..32fe5730 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -1150,10 +1150,44 @@ JSONParser::handleToken()
break;
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:
+ 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:
+ 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:
- // 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;
case ls_number:
@@ -1235,41 +1269,6 @@ JSONParser::handleToken()
break;
// 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