Skip to content

Commit

Permalink
Merge pull request #14007 from Snuffleupagus/writeValue-null
Browse files Browse the repository at this point in the history
[src/core/writer.js] Support `null` values in the `writeValue` function
  • Loading branch information
Snuffleupagus authored Sep 12, 2021
2 parents 8f72fc5 + 7025b9f commit 064c21d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/core/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function writeValue(value, buffer, transform) {
writeDict(value, buffer, transform);
} else if (isStream(value)) {
writeStream(value, buffer, transform);
} else if (value === null) {
buffer.push("null");
} else {
warn(`Unhandled value in writer: ${typeof value}, please file a bug.`);
}
Expand Down
6 changes: 5 additions & 1 deletion test/unit/writer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ describe("Writer", function () {
dict.set("J", true);
dict.set("K", false);

dict.set("NullArr", [null, 10]);
dict.set("NullVal", null);

const buffer = [];
writeDict(dict, buffer, null);

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

expect(buffer.join("")).toEqual(expected);
});
Expand Down

0 comments on commit 064c21d

Please sign in to comment.