Don't decode name of the checkboxes exported values (bug 2022700)

This commit is contained in:
Calixte Denizet 2026-04-22 17:38:04 +02:00
parent 56d730e975
commit 42ccca7ee8
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
4 changed files with 31 additions and 10 deletions

View File

@ -1970,11 +1970,12 @@ class WidgetAnnotation extends Annotation {
*/
_decodeFormValue(formValue) {
if (Array.isArray(formValue)) {
return formValue
.filter(item => typeof item === "string")
.map(item => stringToPDFString(item));
const arr = formValue
.map(item => this._decodeFormValue(item))
.filter(item => item !== null);
return arr.length > 0 ? arr : null;
} else if (formValue instanceof Name) {
return stringToPDFString(formValue.name);
return formValue.name;
} else if (typeof formValue === "string") {
return stringToPDFString(formValue);
}
@ -3419,7 +3420,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
? this.data.fieldValue
: "Yes";
const exportValues = this._decodeFormValue([...normalAppearance.getKeys()]);
// Don't decode the keys which are names.
const exportValues = [...normalAppearance.getKeys()];
if (exportValues.length === 0) {
exportValues.push("Off", yes);
} else if (exportValues.length === 1) {
@ -3491,7 +3493,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
}
for (const key of normalAppearance.getKeys()) {
if (key !== "Off") {
this.data.buttonValue = this._decodeFormValue(key);
this.data.buttonValue = key;
break;
}
}

View File

@ -0,0 +1 @@
https://bugzilla.mozilla.org/attachment.cgi?id=9552059

View File

@ -14143,5 +14143,22 @@
"md5": "29c23022ab3d983733e1ee37fd0bc785",
"rounds": 1,
"type": "eq"
},
{
"id": "bug2022700",
"file": "pdfs/bug2022700.pdf",
"md5": "27c147191aa76a9f9916b3ede76a9523",
"link": true,
"rounds": 1,
"firstPage": 1,
"lastPage": 1,
"save": true,
"print": true,
"annotationStorage": {
"35R": {
"value": true
}
},
"type": "eq"
}
]

View File

@ -2930,10 +2930,11 @@ describe("annotation", function () {
it("should handle radio buttons with a field value that's not an ASCII string", async function () {
const parentDict = new Dict();
parentDict.set("V", Name.get("\x91I=\x91\xf0\x93\xe0\x97e3"));
const name = "\x91I=\x91\xf0\x93\xe0\x97e3";
parentDict.set("V", Name.get(name));
const normalAppearanceStateDict = new Dict();
normalAppearanceStateDict.set("\x91I=\x91\xf0\x93\xe0\x97e3", null);
normalAppearanceStateDict.set(name, null);
const appearanceStatesDict = new Dict();
appearanceStatesDict.set("N", normalAppearanceStateDict);
@ -2956,8 +2957,8 @@ describe("annotation", function () {
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
expect(data.checkBox).toEqual(false);
expect(data.radioButton).toEqual(true);
expect(data.fieldValue).toEqual("I=ðfiàŠe3");
expect(data.buttonValue).toEqual("I=ðfiàŠe3");
expect(data.fieldValue).toEqual(name);
expect(data.buttonValue).toEqual(name);
});
it("should handle radio buttons without a field value", async function () {