Commit 77d1a0cf24e3373948327c37b93e2f0cf86142fd

Authored by m-holger
Committed by GitHub
2 parents 84555e8b 7a1ec75e

Merge pull request #1262 from m-holger/i1261

Fix writing reals with trailing '.' as JSON (fixes #1261)
ChangeLog
  1 +2024-08-06 M Holger <m.holger@qpdf.org>
  2 +
  3 + * Bug fix: when writing real numbers as JSON ensure that they don't
  4 + have a trailing decimal point. Fixes #1261.
  5 +
1 2024-07-14 M Holger <m.holger@qpdf.org> 6 2024-07-14 M Holger <m.holger@qpdf.org>
2 7
3 * Bug fix: handle named destinations where the entry is a 8 * Bug fix: handle named destinations where the entry is a
libqpdf/QPDF_Real.cc
@@ -52,4 +52,7 @@ QPDF_Real::writeJSON(int json_version, JSON::Writer&amp; p) @@ -52,4 +52,7 @@ QPDF_Real::writeJSON(int json_version, JSON::Writer&amp; p)
52 } else { 52 } else {
53 p << this->val; 53 p << this->val;
54 } 54 }
  55 + if (val.back() == '.') {
  56 + p << "0";
  57 + }
55 } 58 }
libtests/json.cc
@@ -111,6 +111,7 @@ test_main() @@ -111,6 +111,7 @@ test_main()
111 check(QPDFObjectHandle::newReal(".34").getJSON(i), "0.34"); 111 check(QPDFObjectHandle::newReal(".34").getJSON(i), "0.34");
112 check(QPDFObjectHandle::newReal("-0.56").getJSON(i), "-0.56"); 112 check(QPDFObjectHandle::newReal("-0.56").getJSON(i), "-0.56");
113 check(QPDFObjectHandle::newReal("-.78").getJSON(i), "-0.78"); 113 check(QPDFObjectHandle::newReal("-.78").getJSON(i), "-0.78");
  114 + check(QPDFObjectHandle::newReal("-78.").getJSON(i), "-78.0");
114 } 115 }
115 JSON jmap2 = JSON::parse(R"({"a": 1, "b": "two", "c": [true]})"); 116 JSON jmap2 = JSON::parse(R"({"a": 1, "b": "two", "c": [true]})");
116 std::map<std::string, std::string> dvalue; 117 std::map<std::string, std::string> dvalue;