mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-05 22:55:49 +02:00
Don't decode name of the checkboxes exported values (bug 2022700)
This commit is contained in:
parent
56d730e975
commit
42ccca7ee8
@ -1970,11 +1970,12 @@ class WidgetAnnotation extends Annotation {
|
|||||||
*/
|
*/
|
||||||
_decodeFormValue(formValue) {
|
_decodeFormValue(formValue) {
|
||||||
if (Array.isArray(formValue)) {
|
if (Array.isArray(formValue)) {
|
||||||
return formValue
|
const arr = formValue
|
||||||
.filter(item => typeof item === "string")
|
.map(item => this._decodeFormValue(item))
|
||||||
.map(item => stringToPDFString(item));
|
.filter(item => item !== null);
|
||||||
|
return arr.length > 0 ? arr : null;
|
||||||
} else if (formValue instanceof Name) {
|
} else if (formValue instanceof Name) {
|
||||||
return stringToPDFString(formValue.name);
|
return formValue.name;
|
||||||
} else if (typeof formValue === "string") {
|
} else if (typeof formValue === "string") {
|
||||||
return stringToPDFString(formValue);
|
return stringToPDFString(formValue);
|
||||||
}
|
}
|
||||||
@ -3419,7 +3420,8 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
? this.data.fieldValue
|
? this.data.fieldValue
|
||||||
: "Yes";
|
: "Yes";
|
||||||
|
|
||||||
const exportValues = this._decodeFormValue([...normalAppearance.getKeys()]);
|
// Don't decode the keys which are names.
|
||||||
|
const exportValues = [...normalAppearance.getKeys()];
|
||||||
if (exportValues.length === 0) {
|
if (exportValues.length === 0) {
|
||||||
exportValues.push("Off", yes);
|
exportValues.push("Off", yes);
|
||||||
} else if (exportValues.length === 1) {
|
} else if (exportValues.length === 1) {
|
||||||
@ -3491,7 +3493,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
}
|
}
|
||||||
for (const key of normalAppearance.getKeys()) {
|
for (const key of normalAppearance.getKeys()) {
|
||||||
if (key !== "Off") {
|
if (key !== "Off") {
|
||||||
this.data.buttonValue = this._decodeFormValue(key);
|
this.data.buttonValue = key;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
test/pdfs/bug2022700.pdf.link
Normal file
1
test/pdfs/bug2022700.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://bugzilla.mozilla.org/attachment.cgi?id=9552059
|
||||||
@ -14143,5 +14143,22 @@
|
|||||||
"md5": "29c23022ab3d983733e1ee37fd0bc785",
|
"md5": "29c23022ab3d983733e1ee37fd0bc785",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -2930,10 +2930,11 @@ describe("annotation", function () {
|
|||||||
|
|
||||||
it("should handle radio buttons with a field value that's not an ASCII string", async function () {
|
it("should handle radio buttons with a field value that's not an ASCII string", async function () {
|
||||||
const parentDict = new Dict();
|
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();
|
const normalAppearanceStateDict = new Dict();
|
||||||
normalAppearanceStateDict.set("\x91I=\x91\xf0\x93\xe0\x97e3", null);
|
normalAppearanceStateDict.set(name, null);
|
||||||
|
|
||||||
const appearanceStatesDict = new Dict();
|
const appearanceStatesDict = new Dict();
|
||||||
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
||||||
@ -2956,8 +2957,8 @@ describe("annotation", function () {
|
|||||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||||
expect(data.checkBox).toEqual(false);
|
expect(data.checkBox).toEqual(false);
|
||||||
expect(data.radioButton).toEqual(true);
|
expect(data.radioButton).toEqual(true);
|
||||||
expect(data.fieldValue).toEqual("‚I=‚ðfiàŠe3");
|
expect(data.fieldValue).toEqual(name);
|
||||||
expect(data.buttonValue).toEqual("‚I=‚ðfiàŠe3");
|
expect(data.buttonValue).toEqual(name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle radio buttons without a field value", async function () {
|
it("should handle radio buttons without a field value", async function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user