Skip to content

Commit f331b16

Browse files
authored
Normalize nullish AcroForm text values to empty strings (#1738)
* Initial plan * Normalize nullish AcroForm text values * Address AcroForm review feedback * Simplify AcroForm value normalization --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 8ca518d commit f331b16

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/mixins/acroform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ export default {
368368
}
369369

370370
Object.keys(VALUE_MAP).forEach((key) => {
371-
if (options[key] !== undefined) {
372-
options[VALUE_MAP[key]] = options[key];
371+
if (key in options) {
372+
options[VALUE_MAP[key]] = options[key] ?? '';
373373
delete options[key];
374374
}
375375
});

tests/unit/acroform.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ describe('acroform', () => {
186186
expect(docData.length).toBe(3);
187187
expect(docData).toContainChunk(expected);
188188
});
189+
190+
test.each([
191+
['undefined', undefined],
192+
['null', null],
193+
])('nullish %s value uses an empty string', (_label, value) => {
194+
const expectedDoc = new PDFDocument({
195+
info: { CreationDate: new Date(Date.UTC(2018, 1, 1)) },
196+
});
197+
expectedDoc.initForm();
198+
const expectedDocData = logData(expectedDoc);
199+
expectedDoc.formText('empty', 20, 20, 50, 20, { value: '' });
200+
201+
doc.initForm();
202+
const docData = logData(doc);
203+
doc.formText('empty', 20, 20, 50, 20, { value });
204+
205+
expect(docData).toContainChunk(expectedDocData);
206+
});
189207
});
190208

191209
test('flags', () => {

0 commit comments

Comments
 (0)