From a9a0667904b467a054b5f7747bc16afba2612d7f Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 27 Jan 2023 17:03:24 +0000 Subject: Make JSONParser::getToken responsible for decoding strings --- libqpdf/JSON.cc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 2a722e67..c043d570 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -1052,6 +1052,9 @@ JSONParser::getToken() case ls_string: if (*p == '"') { + token += '"'; + token = decode_string(token, token_start); + action = ignore; ready = true; } else if (*p == '\\') { lex_state = ls_backslash; @@ -1146,7 +1149,6 @@ JSONParser::handleToken() ": material follows end of object: " + token); } - std::string s_value; std::shared_ptr item; auto tos = stack.empty() ? nullptr : stack.back().item; auto ls = lex_state; @@ -1245,19 +1247,14 @@ JSONParser::handleToken() break; case ls_string: - // Token includes the quotation marks - if (token.length() < 2) { - throw std::logic_error("JSON string length < 2"); - } - s_value = decode_string(token, token_start); if (parser_state == ps_dict_begin || parser_state == ps_dict_after_comma) { - dict_key = s_value; + dict_key = token; dict_key_offset = token_start; parser_state = ps_dict_after_key; return; } else { - item = std::make_shared(JSON::makeString(s_value)); + item = std::make_shared(JSON::makeString(token)); } break; -- cgit v1.2.3-54-g00ecf