diff options
author | m-holger <m-holger@kubitscheck.org> | 2023-01-24 01:44:16 +0100 |
---|---|---|
committer | m-holger <m-holger@kubitscheck.org> | 2023-02-01 15:01:57 +0100 |
commit | b6b4d3b299490966524ee5a1a8ecc03c267af0c8 (patch) | |
tree | 1f6331f1e25289b5f0b9d84caabf75504c1295b6 /libqpdf/JSON.cc | |
parent | 1787d85096c47bb3986b529af2a118793179a040 (diff) | |
download | qpdf-b6b4d3b299490966524ee5a1a8ecc03c267af0c8.tar.zst |
Add new method JSONParser::numberError
Diffstat (limited to 'libqpdf/JSON.cc')
-rw-r--r-- | libqpdf/JSON.cc | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 77418ddb..5205d4f9 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -620,6 +620,7 @@ namespace private: void getToken(); void handleToken(); + void numberError(); static std::string decode_string(std::string const& json, qpdf_offset_t offset); static void handle_u_code( @@ -797,6 +798,39 @@ JSONParser::decode_string(std::string const& str, qpdf_offset_t offset) } void +JSONParser::numberError() +{ + if (*p == '.') { + if (number_saw_e) { + // QTC::TC("libtests", "JSON parse point after e"); + throw std::runtime_error( + "JSON: offset " + std::to_string(offset) + + ": numeric literal: decimal point after e"); + } else { + // QTC::TC("libtests", "JSON parse duplicate point"); + throw std::runtime_error( + "JSON: offset " + std::to_string(offset) + + ": numeric literal: decimal point already seen"); + } + } else if (*p == 'e') { + // QTC::TC("libtests", "JSON parse duplicate e"); + throw std::runtime_error( + "JSON: offset " + std::to_string(offset) + + ": numeric literal: e already seen"); + } else if ((*p == '+') || (*p == '-')) { + // QTC::TC("libtests", "JSON parse unexpected sign"); + throw std::runtime_error( + "JSON: offset " + std::to_string(offset) + + ": numeric literal: unexpected sign"); + } else { + QTC::TC("libtests", "JSON parse numeric bad character"); + throw std::runtime_error( + "JSON: offset " + std::to_string(offset) + + ": numeric literal: unexpected character " + std::string(p, 1)); + } +} + +void JSONParser::getToken() { enum { append, ignore, reread } action = append; @@ -905,11 +939,7 @@ JSONParser::getToken() action = reread; ready = true; } else { - QTC::TC("libtests", "JSON parse numeric bad character"); - throw std::runtime_error( - "JSON: offset " + std::to_string(offset) + - ": numeric literal: unexpected character " + - std::string(p, 1)); + numberError(); } break; |