From 7a1ec75ee1010942c873258fb7a786e677dee9df Mon Sep 17 00:00:00 2001 From: m-holger Date: Tue, 6 Aug 2024 00:21:23 +0100 Subject: [PATCH] Fix writing reals with trailing '.' as JSON (fixes #1261) --- ChangeLog | 5 +++++ libqpdf/QPDF_Real.cc | 3 +++ libtests/json.cc | 1 + 3 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9c31c781..6968781c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-08-06 M Holger + + * Bug fix: when writing real numbers as JSON ensure that they don't + have a trailing decimal point. Fixes #1261. + 2024-07-14 M Holger * Bug fix: handle named destinations where the entry is a diff --git a/libqpdf/QPDF_Real.cc b/libqpdf/QPDF_Real.cc index f4304397..df3eaa61 100644 --- a/libqpdf/QPDF_Real.cc +++ b/libqpdf/QPDF_Real.cc @@ -52,4 +52,7 @@ QPDF_Real::writeJSON(int json_version, JSON::Writer& p) } else { p << this->val; } + if (val.back() == '.') { + p << "0"; + } } diff --git a/libtests/json.cc b/libtests/json.cc index 4f4cff8e..b17434ac 100644 --- a/libtests/json.cc +++ b/libtests/json.cc @@ -111,6 +111,7 @@ test_main() check(QPDFObjectHandle::newReal(".34").getJSON(i), "0.34"); check(QPDFObjectHandle::newReal("-0.56").getJSON(i), "-0.56"); check(QPDFObjectHandle::newReal("-.78").getJSON(i), "-0.78"); + check(QPDFObjectHandle::newReal("-78.").getJSON(i), "-78.0"); } JSON jmap2 = JSON::parse(R"({"a": 1, "b": "two", "c": [true]})"); std::map dvalue;