mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Decode widget form values consistently
The helper method `_decodeFormValue` is used to ensure that it happens in one place. Note that form values are field values, display values and export values.
This commit is contained in:
parent
36e149800e
commit
1b82ad8fff
2 changed files with 43 additions and 19 deletions
|
@ -2450,16 +2450,12 @@ describe("annotation", function () {
|
|||
}, done.fail);
|
||||
});
|
||||
|
||||
it("should sanitize display values in option arrays (issue 8947)", function (done) {
|
||||
// The option value is a UTF-16BE string. The display value should be
|
||||
// sanitized, but the export value should remain the same since that
|
||||
// may be used as a unique identifier when exporting form values.
|
||||
const options = ["\xFE\xFF\x00F\x00o\x00o"];
|
||||
const expected = [
|
||||
{ exportValue: "\xFE\xFF\x00F\x00o\x00o", displayValue: "Foo" },
|
||||
];
|
||||
it("should decode form values", function (done) {
|
||||
const encodedString = "\xFE\xFF\x00F\x00o\x00o";
|
||||
const decodedString = "Foo";
|
||||
|
||||
choiceWidgetDict.set("Opt", options);
|
||||
choiceWidgetDict.set("Opt", [encodedString]);
|
||||
choiceWidgetDict.set("V", encodedString);
|
||||
|
||||
const choiceWidgetRef = Ref.get(984, 0);
|
||||
const xref = new XRefMock([
|
||||
|
@ -2473,7 +2469,10 @@ describe("annotation", function () {
|
|||
idFactoryMock
|
||||
).then(({ data }) => {
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
expect(data.options).toEqual(expected);
|
||||
expect(data.fieldValue).toEqual([decodedString]);
|
||||
expect(data.options).toEqual([
|
||||
{ exportValue: decodedString, displayValue: decodedString },
|
||||
]);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue