2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Make JSONParser::getToken responsible for decoding strings

This commit is contained in:
m-holger 2023-01-27 17:03:24 +00:00
parent 126dd31cad
commit a9a0667904

View File

@ -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<JSON> 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>(JSON::makeString(s_value));
item = std::make_shared<JSON>(JSON::makeString(token));
}
break;