Add additional name token JSON tests

Also, test writing JSON v1 files and files with deeply nested containers.
This commit is contained in:
m-holger 2024-02-10 19:26:40 +00:00
parent d28969bf37
commit 9379b76811
5 changed files with 715 additions and 10 deletions

View File

@ -350,7 +350,7 @@ $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 += 4;
$n_tests += 6;
$td->runtest("handle binary names",
{$td->COMMAND =>
"qpdf --json-output weird-tokens.pdf a.json"},
@ -371,6 +371,14 @@ $td->runtest("weird tokens with scientific notation",
"qpdf --json-input --json-output weird-tokens-alt.json -"},
{$td->FILE => "weird-tokens.json", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("handle binary names (JSON v1)",
{$td->COMMAND =>
"qpdf --json=1 weird-tokens.pdf a.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check json",
{$td->FILE => "a.json"},
{$td->FILE => "weird-tokens-v1.json"},
$td->NORMALIZE_NEWLINES);
cleanup();
$td->report($n_tests);

View File

@ -10,21 +10,155 @@
{
"obj:1 0 R": {
"value": {
"/Escape\\Key": 42,
"/Extra": [
"u:Names with binary data",
"n:/ABCDEF+#ba#da#cc#e5",
"n:/OVERLONG+#c0#81",
"n:/OVERLONG+#c1#ff",
"/Ok+€",
"n:/OVERLONG+#e0#81#82",
"n:/OVERLONG+#e0#9f#ff",
"/Ok+ࠀ",
"n:/OVERLONG+#f0#81#82#83",
"n:/OVERLONG+#f0#8f#ff#ff",
"/Ok+𐀀",
"n:/range+#01",
"n:/low+#18",
"/ABCEDEF+π",
"n:/one+#a0two",
"n:/text#2fplain",
"u:Names requiring escaping in JSON",
"/Back\\shlash",
"/Low\u0022",
"/Low\u001f",
"/ExceptSpace ",
"/Except!",
"u:Very small/large reals",
1e-05,
1e12
],
"/Nested": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": 42
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/Pages": "2 0 R",
"/Type": "/Catalog",
"n:/WeirdKey+#ba#da#cc#e5": 42
@ -78,7 +212,7 @@
"value": {
"/ID": [
"b:42841c13bbf709d79a200fa1691836f8",
"b:728c020f464c3cf7e02c12605fa7d88b"
"b:31415926535897932384626433832795"
],
"/Root": "1 0 R",
"/Size": 7

View File

@ -0,0 +1,295 @@
{
"version": 1,
"parameters": {
"decodelevel": "generalized"
},
"pages": [
{
"contents": [
"4 0 R"
],
"images": [],
"label": null,
"object": "3 0 R",
"outlines": [],
"pageposfrom1": 1
}
],
"pagelabels": [],
"acroform": {
"fields": [],
"hasacroform": false,
"needappearances": false
},
"attachments": {},
"encrypt": {
"capabilities": {
"accessibility": true,
"extract": true,
"moddifyannotations": true,
"modify": true,
"modifyassembly": true,
"modifyforms": true,
"modifyother": true,
"printhigh": true,
"printlow": true
},
"encrypted": false,
"ownerpasswordmatched": false,
"parameters": {
"P": 0,
"R": 0,
"V": 0,
"bits": 0,
"filemethod": "none",
"key": null,
"method": "none",
"streammethod": "none",
"stringmethod": "none"
},
"recovereduserpassword": null,
"userpasswordmatched": false
},
"outlines": [],
"objects": {
"1 0 R": {
"/Escape\\Key": 42,
"/Extra": [
"Names with binary data",
"/ABCDEF+#ba#da#cc#e5",
"/OVERLONG+#c0#81",
"/OVERLONG+#c1#ff",
"/Ok+#c2#80",
"/OVERLONG+#e0#81#82",
"/OVERLONG+#e0#9f#ff",
"/Ok+#e0#a0#80",
"/OVERLONG+#f0#81#82#83",
"/OVERLONG+#f0#8f#ff#ff",
"/Ok+#f0#90#80#80",
"/range+#01",
"/low+#18",
"/ABCEDEF+#cf#80",
"/one+#a0two",
"/text#2fplain",
"Names requiring escaping in JSON",
"/Back\\shlash",
"/Low\"",
"/Low#1f",
"/ExceptSpace#20",
"/Except!",
"Very small/large reals",
0.00001,
1000000000000
],
"/Nested": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": 42
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/Pages": "2 0 R",
"/Type": "/Catalog",
"/WeirdKey+#ba#da#cc#e5": 42
},
"2 0 R": {
"/Count": 1,
"/Kids": [
"3 0 R"
],
"/Type": "/Pages"
},
"3 0 R": {
"/Contents": "4 0 R",
"/MediaBox": [
0,
0,
612,
792
],
"/Parent": "2 0 R",
"/Resources": {
"/Font": {
"/F1": "6 0 R"
}
},
"/Type": "/Page"
},
"4 0 R": {
"/Length": "5 0 R"
},
"5 0 R": 44,
"6 0 R": {
"/BaseFont": "/Helvetica",
"/Encoding": "/WinAnsiEncoding",
"/Subtype": "/Type1",
"/Type": "/Font"
},
"trailer": {
"/ID": [
"B—˝\u0013»÷\t×ı \u000f¡i˘6ø",
"1AY&SXŠfi#—bd3…'Ł"
],
"/Root": "1 0 R",
"/Size": 7
}
},
"objectinfo": {
"1 0 R": {
"stream": {
"filter": null,
"is": false,
"length": null
}
},
"2 0 R": {
"stream": {
"filter": null,
"is": false,
"length": null
}
},
"3 0 R": {
"stream": {
"filter": null,
"is": false,
"length": null
}
},
"4 0 R": {
"stream": {
"filter": null,
"is": true,
"length": 44
}
},
"5 0 R": {
"stream": {
"filter": null,
"is": false,
"length": null
}
},
"6 0 R": {
"stream": {
"filter": null,
"is": false,
"length": null
}
}
}
}

View File

@ -10,21 +10,155 @@
{
"obj:1 0 R": {
"value": {
"/Escape\\Key": 42,
"/Extra": [
"u:Names with binary data",
"n:/ABCDEF+#ba#da#cc#e5",
"n:/OVERLONG+#c0#81",
"n:/OVERLONG+#c1#ff",
"/Ok+€",
"n:/OVERLONG+#e0#81#82",
"n:/OVERLONG+#e0#9f#ff",
"/Ok+ࠀ",
"n:/OVERLONG+#f0#81#82#83",
"n:/OVERLONG+#f0#8f#ff#ff",
"/Ok+𐀀",
"/range+\u0001",
"/low+\u0018",
"/ABCEDEF+π",
"n:/one+#a0two",
"/text/plain",
"u:Names requiring escaping in JSON",
"/Back\\shlash",
"/Low\"",
"/Low\u001f",
"/ExceptSpace ",
"/Except!",
"u:Very small/large reals",
0.00001,
1000000000000
],
"/Nested": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": {
"/1": {
"/2": {
"/3": {
"/4": {
"/5": {
"/6": {
"/7": {
"/8": {
"/9": {
"/10": 42
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/Pages": "2 0 R",
"/Type": "/Catalog",
"n:/WeirdKey+#ba#da#cc#e5": 42
@ -78,7 +212,7 @@
"value": {
"/ID": [
"b:42841c13bbf709d79a200fa1691836f8",
"b:728c020f464c3cf7e02c12605fa7d88b"
"b:31415926535897932384626433832795"
],
"/Root": "1 0 R",
"/Size": 7

View File

@ -4,21 +4,155 @@
1 0 obj
<<
/Escape\Key 42
/Extra [
(Names with binary data)
/ABCDEF+#ba#da#cc#e5
/OVERLONG+#c0#81
/OVERLONG+#c1#ff
/Ok+#c2#80
/OVERLONG+#e0#81#82
/OVERLONG+#e0#9f#ff
/Ok+#e0#a0#80
/OVERLONG+#f0#81#82#83
/OVERLONG+#f0#8f#ff#ff
/Ok+#f0#90#80#80
/range+#01
/low+#18
/ABCEDEF+#cf#80
/one+#a0two
/text#2fplain
(Names requiring escaping in JSON)
/Back\shlash
/Low"
/Low#1f
/ExceptSpace#20
/Except!
(Very small/large reals)
0.00001
1000000000000
]
/Nested <<
/1 <<
/2 <<
/3 <<
/4 <<
/5 <<
/6 <<
/7 <<
/8 <<
/9 <<
/10 <<
/1 <<
/2 <<
/3 <<
/4 <<
/5 <<
/6 <<
/7 <<
/8 <<
/9 <<
/10 <<
/1 <<
/2 <<
/3 <<
/4 <<
/5 <<
/6 <<
/7 <<
/8 <<
/9 <<
/10 <<
/1 <<
/2 <<
/3 <<
/4 <<
/5 <<
/6 <<
/7 <<
/8 <<
/9 <<
/10 <<
/1 <<
/2 <<
/3 <<
/4 <<
/5 <<
/6 <<
/7 <<
/8 <<
/9 <<
/10 <<
/1 <<
/2 <<
/3 <<
/4 <<
/5 <<
/6 <<
/7 <<
/8 <<
/9 <<
/10 42
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
/Pages 2 0 R
/Type /Catalog
/WeirdKey+#ba#da#cc#e5 42
@ -86,16 +220,16 @@ xref
0 7
0000000000 65535 f
0000000025 00000 n
0000000389 00000 n
0000000471 00000 n
0000000667 00000 n
0000000766 00000 n
0000000785 00000 n
0000008642 00000 n
0000008724 00000 n
0000008920 00000 n
0000009019 00000 n
0000009038 00000 n
trailer <<
/Root 1 0 R
/Size 7
/ID [<42841c13bbf709d79a200fa1691836f8><728c020f464c3cf7e02c12605fa7d88b>]
/ID [<42841c13bbf709d79a200fa1691836f8><31415926535897932384626433832795>]
>>
startxref
891
9144
%%EOF