Skip to content

Commit c0eb7f8

Browse files
committed
[src/core/writer.js] Support null values in the writeValue function
*This fixes something that I noticed, having recently looked at both the `Lexer.getObj` and `writeValue` code.* Please note that I unfortunately don't have an example of a form where saving fails without this patch. However, given its overall simplicity and that unit-tests are added, it's hopefully deemed useful to fix this potential issue pro-actively rather than waiting for a bug report. At the point one might, and rightly so, wonder if there's actually any real-world PDF documents where a `null` value is being used? Unfortunately the answer is *yes*, and we have a couple of examples in the test-suite (although none of those are related to forms); please see: `issue1015`, `issue2642`, `issue10402`, `issue12823`, `issue13823`, and `pr12564`.
1 parent 8f72fc5 commit c0eb7f8

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/core/writer.js

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ function writeValue(value, buffer, transform) {
8989
writeDict(value, buffer, transform);
9090
} else if (isStream(value)) {
9191
writeStream(value, buffer, transform);
92+
} else if (value === null) {
93+
buffer.push("null");
9294
} else {
9395
warn(`Unhandled value in writer: ${typeof value}, please file a bug.`);
9496
}

test/unit/writer_spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ describe("Writer", function () {
117117
dict.set("J", true);
118118
dict.set("K", false);
119119

120+
dict.set("NullArr", [null, 10]);
121+
dict.set("NullVal", null);
122+
120123
const buffer = [];
121124
writeDict(dict, buffer, null);
122125

@@ -125,7 +128,8 @@ describe("Writer", function () {
125128
"/E (\\(hello\\\\world\\)) /F [1.23 4.5 6] " +
126129
"/G << /H 123 /I << /Length 8>> stream\n" +
127130
"a stream\n" +
128-
"endstream\n>> /J true /K false>>";
131+
"endstream\n>> /J true /K false " +
132+
"/NullArr [null 10] /NullVal null>>";
129133

130134
expect(buffer.join("")).toEqual(expected);
131135
});

0 commit comments

Comments
 (0)