aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-01-27 14:08:55 +0100
committerm-holger <m-holger@kubitscheck.org>2023-02-04 14:53:23 +0100
commitf2e46c20b62aa72a984b99c816176cfa3367a6e7 (patch)
tree623b51306b73b9c1072bd303e2e298f71dd91ebe /libqpdf
parent0de032bcdd49d50df6a3e4a2e6325e5144c4619e (diff)
downloadqpdf-f2e46c20b62aa72a984b99c816176cfa3367a6e7.tar.zst
In JSONParser::handleToken move remaining validations into second switch statement
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/JSON.cc71
1 files changed, 21 insertions, 50 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc
index 1749005b..174a46b6 100644
--- a/libqpdf/JSON.cc
+++ b/libqpdf/JSON.cc
@@ -1252,56 +1252,6 @@ JSONParser::handleToken()
break;
}
- // See whether what we have is allowed at this point.
-
- if (item.get()) {
- switch (parser_state) {
- case ps_done:
- throw std::logic_error("can't happen; ps_done already handled");
- break;
-
- case ps_dict_after_key:
- QTC::TC("libtests", "JSON parse expected colon");
- throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) + ": expected ':'");
- break;
-
- case ps_dict_after_item:
- QTC::TC("libtests", "JSON parse expected , or }");
- throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": expected ',' or '}'");
- break;
-
- case ps_array_after_item:
- QTC::TC("libtests", "JSON parse expected, or ]");
- throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": expected ',' or ']'");
- break;
-
- case ps_dict_begin:
- case ps_dict_after_comma:
- if (lex_state != ls_string) {
- QTC::TC("libtests", "JSON parse string as dict key");
- throw std::runtime_error(
- "JSON: offset " + std::to_string(offset) +
- ": expect string as dictionary key");
- }
- break;
-
- case ps_top:
- case ps_dict_after_colon:
- case ps_array_begin:
- case ps_array_after_comma:
- break;
- // okay
- }
- }
-
- // Now we know we have a delimiter or item that is allowed. Do
- // whatever we need to do with it.
-
parser_state_e next_state = ps_top;
item->setStart(token_start);
@@ -1310,6 +1260,12 @@ JSONParser::handleToken()
switch (parser_state) {
case ps_dict_begin:
case ps_dict_after_comma:
+ if (lex_state != ls_string) {
+ QTC::TC("libtests", "JSON parse string as dict key");
+ throw std::runtime_error(
+ "JSON: offset " + std::to_string(offset) +
+ ": expect string as dictionary key");
+ }
this->dict_key = s_value;
this->dict_key_offset = item->getStart();
item = nullptr;
@@ -1342,8 +1298,23 @@ JSONParser::handleToken()
break;
case ps_dict_after_key:
+ QTC::TC("libtests", "JSON parse expected colon");
+ throw std::runtime_error(
+ "JSON: offset " + std::to_string(offset) + ": expected ':'");
+ break;
+
case ps_dict_after_item:
+ QTC::TC("libtests", "JSON parse expected , or }");
+ throw std::runtime_error(
+ "JSON: offset " + std::to_string(offset) + ": expected ',' or '}'");
+ break;
+
case ps_array_after_item:
+ QTC::TC("libtests", "JSON parse expected, or ]");
+ throw std::runtime_error(
+ "JSON: offset " + std::to_string(offset) + ": expected ',' or ']'");
+ break;
+
case ps_done:
throw std::logic_error(
"JSONParser::handleToken: unexpected parser state");