Skip to content

Commit

Permalink
Fix Acroforms - setting an option to false will still apply the flag (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
RicoBrase committed Feb 7, 2024
1 parent a655194 commit 485b7e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
- Fix for line breaks in list items (#1486)
- Fix for soft hyphen not being replaced by visible hyphen if necessary (#457)
- Optimize output files by ignoring identity transforms
- Fix for Acroforms - setting an option to false will still apply the flag (#1495)

### [v0.14.0] - 2023-11-09

Expand Down
4 changes: 3 additions & 1 deletion lib/mixins/acroform.js
Expand Up @@ -299,7 +299,9 @@ export default {
let result = 0;
Object.keys(options).forEach(key => {
if (FIELD_FLAGS[key]) {
result |= FIELD_FLAGS[key];
if (options[key]) {
result |= FIELD_FLAGS[key];
}
delete options[key];
}
});
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/acroform.spec.js
Expand Up @@ -212,6 +212,33 @@ describe('acroform', () => {
expect(docData).toContainChunk(expected);
});

test('false flags should be ignored', () => {
const expectedDoc = new PDFDocument({
info: { CreationDate: new Date(Date.UTC(2018, 1, 1)) }
});
expectedDoc.initForm();
const expectedDocData = logData(expectedDoc);
let emptyOpts = {
align: 'center'
};
expectedDoc.formText('flags', 20, 20, 50, 20, emptyOpts);

doc.initForm();
const docData = logData(doc);
let opts = {
required: false,
noExport: false,
readOnly: false,
align: 'center',
multiline: false,
password: false,
noSpell: false
};
doc.formText('flags', 20, 20, 50, 20, opts);

expect(docData).toContainChunk(expectedDocData);
});

test('font size', () => {
const expected = [
'11 0 obj',
Expand Down

0 comments on commit 485b7e6

Please sign in to comment.