aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2023-12-21 23:38:49 +0100
committerJay Berkenbilt <ejb@ql.org>2023-12-21 23:56:30 +0100
commitb670565abc579de5bda946b7538545aa967e6cd2 (patch)
tree9fe90b9183ba8c884b69e1e21cc06a1dba280f4f /qpdf
parent4400ce84eeb204cdcb35950dd8fde094fc249051 (diff)
downloadqpdf-b670565abc579de5bda946b7538545aa967e6cd2.tar.zst
Convert scientific notation in JSON to fixed point (fixes #1079)
JSON accepts scientific notation, but PDF doesn't.
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qtest/qpdf-json.test15
-rw-r--r--qpdf/qtest/qpdf/weird-tokens-alt.json83
2 files changed, 96 insertions, 2 deletions
diff --git a/qpdf/qtest/qpdf-json.test b/qpdf/qtest/qpdf-json.test
index 9691d995..0ea126ec 100644
--- a/qpdf/qtest/qpdf-json.test
+++ b/qpdf/qtest/qpdf-json.test
@@ -347,16 +347,27 @@ $td->runtest("check C API write to JSON stream",
# (using #xx) would generate invalid JSON, even though qpdf's own JSON
# parser would accept it. Also, the JSON spec allows real numbers in
# scientific notation, but the PDF spec does not.
-$n_tests += 2;
+$n_tests += 4;
$td->runtest("handle binary names",
{$td->COMMAND =>
"qpdf --json-output weird-tokens.pdf a.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
-# Round-trip is tested above.
+# Round-trip back to PDF is tested above.
$td->runtest("check json",
{$td->FILE => "a.json"},
{$td->FILE => "weird-tokens.json"},
$td->NORMALIZE_NEWLINES);
+# Make sure we can properly handle JSON with scientific notation.
+$td->runtest("weird tokens round trip json",
+ {$td->COMMAND =>
+ "qpdf --json-input --json-output weird-tokens.json -"},
+ {$td->FILE => "weird-tokens.json", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("weird tokens with scientific notation",
+ {$td->COMMAND =>
+ "qpdf --json-input --json-output weird-tokens-alt.json -"},
+ {$td->FILE => "weird-tokens.json", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
cleanup();
$td->report($n_tests);
diff --git a/qpdf/qtest/qpdf/weird-tokens-alt.json b/qpdf/qtest/qpdf/weird-tokens-alt.json
new file mode 100644
index 00000000..5a9f8ff8
--- /dev/null
+++ b/qpdf/qtest/qpdf/weird-tokens-alt.json
@@ -0,0 +1,83 @@
+{
+ "qpdf": [
+ {
+ "jsonversion": 2,
+ "pdfversion": "2.0",
+ "pushedinheritedpageresources": false,
+ "calledgetallpages": false,
+ "maxobjectid": 6
+ },
+ {
+ "obj:1 0 R": {
+ "value": {
+ "/Extra": [
+ "u:Names with binary data",
+ "n:/ABCDEF+#ba#da#cc#e5",
+ "/ABCEDEF+π",
+ "n:/one+#a0two",
+ "n:/text#2fplain",
+ "u:Very small/large reals",
+ 1e-05,
+ 1e12
+ ],
+ "/Pages": "2 0 R",
+ "/Type": "/Catalog"
+ }
+ },
+ "obj:2 0 R": {
+ "value": {
+ "/Count": 1,
+ "/Kids": [
+ "3 0 R"
+ ],
+ "/Type": "/Pages"
+ }
+ },
+ "obj:3 0 R": {
+ "value": {
+ "/Contents": "4 0 R",
+ "/MediaBox": [
+ 0,
+ 0,
+ 612,
+ 792
+ ],
+ "/Parent": "2 0 R",
+ "/Resources": {
+ "/Font": {
+ "/F1": "6 0 R"
+ }
+ },
+ "/Type": "/Page"
+ }
+ },
+ "obj:4 0 R": {
+ "stream": {
+ "data": "QlQKICAvRjEgMjQgVGYKICA3MiA3MjAgVGQKICAoUG90YXRvKSBUagpFVAo=",
+ "dict": {}
+ }
+ },
+ "obj:5 0 R": {
+ "value": 44
+ },
+ "obj:6 0 R": {
+ "value": {
+ "/BaseFont": "/Helvetica",
+ "/Encoding": "/WinAnsiEncoding",
+ "/Subtype": "/Type1",
+ "/Type": "/Font"
+ }
+ },
+ "trailer": {
+ "value": {
+ "/ID": [
+ "b:42841c13bbf709d79a200fa1691836f8",
+ "b:728c020f464c3cf7e02c12605fa7d88b"
+ ],
+ "/Root": "1 0 R",
+ "/Size": 7
+ }
+ }
+ }
+ ]
+}