diff options
author | Jay Berkenbilt <ejb@ql.org> | 2023-12-21 23:38:49 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2023-12-21 23:56:30 +0100 |
commit | b670565abc579de5bda946b7538545aa967e6cd2 (patch) | |
tree | 9fe90b9183ba8c884b69e1e21cc06a1dba280f4f /libqpdf/QPDF_json.cc | |
parent | 4400ce84eeb204cdcb35950dd8fde094fc249051 (diff) | |
download | qpdf-b670565abc579de5bda946b7538545aa967e6cd2.tar.zst |
Convert scientific notation in JSON to fixed point (fixes #1079)
JSON accepts scientific notation, but PDF doesn't.
Diffstat (limited to 'libqpdf/QPDF_json.cc')
-rw-r--r-- | libqpdf/QPDF_json.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 864e1a56..7951b1e4 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -732,6 +732,15 @@ QPDF::JSONReactor::makeObject(JSON const& value) if (QUtil::is_long_long(str_v.c_str())) { result = QPDFObjectHandle::newInteger(QUtil::string_to_ll(str_v.c_str())); } else { + // JSON allows scientific notation, but PDF does not. + if (str_v.find('e') != std::string::npos || str_v.find('E') != std::string::npos) { + try { + auto v = std::stod(str_v); + str_v = QUtil::double_to_string(v); + } catch (std::exception&) { + // Keep it as it was + } + } result = QPDFObjectHandle::newReal(str_v); } } else if (value.getString(str_v)) { |