Skip to content

Write boolean value when saving a form (bug 1729971) #13998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ function writeValue(value, buffer, transform) {
buffer.push(`(${escapeString(value)})`);
} else if (typeof value === "number") {
buffer.push(numberToString(value));
} else if (typeof value === "boolean") {
buffer.push(`${value.toString()}`);
Copy link
Collaborator

@Snuffleupagus Snuffleupagus Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something obvious here, but why do you need to wrap this in a string?
Isn't value.toString() already a string, in which case just buffer.push(value.toString()); ought to work.

} else if (isDict(value)) {
writeDict(value, buffer, transform);
} else if (isStream(value)) {
writeStream(value, buffer, transform);
} else {
warn(`Unhandled value in writer: ${typeof value}, please file a bug.`);
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/unit/writer_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ describe("Writer", function () {
gdict.set("I", stream);

dict.set("G", gdict);
dict.set("J", true);
dict.set("K", false);

const buffer = [];
writeDict(dict, buffer, null);
Expand All @@ -123,7 +125,7 @@ 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>>>>";
"endstream\n>> /J true /K false>>";

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