Skip to content

Normalize nullish AcroForm text values to empty strings#1738

Draft
Copilot wants to merge 4 commits into
masterfrom
copilot/fix-acroforms-undefined-option
Draft

Normalize nullish AcroForm text values to empty strings#1738
Copilot wants to merge 4 commits into
masterfrom
copilot/fix-acroforms-undefined-option

Conversation

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Passing undefined into doc.formText() could serialize the literal token undefined into the field dictionary, producing an invalid PDF that breaks parsers such as pdf-lib and iText RUPS. This change normalizes explicit nullish text values to empty strings so AcroForm output remains valid.

  • AcroForm value normalization

    • Treat explicit value: undefined, value: null, defaultValue: undefined, and defaultValue: null as '' during field dictionary construction.
    • Preserve existing behavior for omitted options by only normalizing keys that are actually present.
  • Regression coverage

    • Add unit coverage for formText() with undefined and null values.
    • Assert those cases serialize identically to an explicit empty string.
  • Example

    doc.formText('demofield', 10, 60, 200, 40, {
      value: undefined,
    });

    Before, this could emit an invalid object value like undefined. With this change, the field is serialized with an empty AcroForm value instead.

Copilot AI changed the title [WIP] Fix Acroforms issue with undefined field option Normalize nullish AcroForm text values to empty strings Jun 13, 2026
Copilot AI requested a review from blikblum June 13, 2026 00:30

@blikblum blikblum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread lib/mixins/acroform.js Outdated
Comment on lines +372 to +376
if (options[key] == null) {
options[VALUE_MAP[key]] = '';
} else {
options[VALUE_MAP[key]] = options[key];
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if (options[key] == null) {
options[VALUE_MAP[key]] = '';
} else {
options[VALUE_MAP[key]] = options[key];
}
options[VALUE_MAP[key]] = options[key] ?? '';

simplify

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot

Updated in 0c92a0e.

Copilot AI requested a review from blikblum June 13, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants