Skip to content
New issue

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

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

Already on GitHub? # to your account

Acroforms - setting an option to false will still apply the flag #1495

Closed
RicoBrase opened this issue Feb 4, 2024 · 0 comments · Fixed by #1496
Closed

Acroforms - setting an option to false will still apply the flag #1495

RicoBrase opened this issue Feb 4, 2024 · 0 comments · Fixed by #1496

Comments

@RicoBrase
Copy link
Contributor

RicoBrase commented Feb 4, 2024

Bug Report

Description of the problem

When using acroforms, setting a boolean option to false will still add the flag to the PDF document.
This is caused by the function resolveFlags(options) in lib/mixins/acroforms.js not checking the value of the options - as long as a corresponding key is set to any value (even undefined), their flag is added to the field.

Example:
The option password is explicitly set to false, but the form text gets rendered with the password flag (only asterisks shown).

image
(Screenshot uses the code sample from below.)

I am currently creating a pull request, which will fix this issue.
PR #1496 is ready.

Code sample

I forked the repo and modified the example in the webpack folder:

var doc = new PDFDocument();
doc.registerFont('Roboto', 'fonts/Roboto-Regular.ttf');

doc.initForm();

var opts = {
    value: "sample",
    password: false
};

doc.formText("example", 100, 100, 200, 40, opts);

// waitForData must be called before call to doc.end()
waitForData(doc)
  .then(dataUrl => {
    // display the document in the iframe to the right
    iframe.src = dataUrl;
  })
  .catch(error => {
    console.log(error);
  });

doc.end();

Your environment

  • pdfkit version: 0.14.0(forked from master)
  • Node version: v20.11.0
  • Browser version (if applicable): Chrome 121.0.6167.139 (arm64)
  • Operating System: macOS Sonoma 14.3 (M1)
RicoBrase added a commit to RicoBrase/pdfkit that referenced this issue Feb 4, 2024
blikblum pushed a commit that referenced this issue Feb 7, 2024
…1496)

* Add an option check to acroform mixin _resolveFlags().

This resolves #1495.

* Reworked fix to remove flags from options, if they are falsey.

* Added unit test for ignoring false flags in acroforms

* Added entry for removing false flags in changelog.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant