Sanitize the display value for choice widget annotations
This commit is contained in:
parent
9e8cf448b0
commit
25b07812b9
@ -798,7 +798,8 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
|
|||||||
|
|
||||||
this.data.options[i] = {
|
this.data.options[i] = {
|
||||||
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
|
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
|
||||||
displayValue: isOptionArray ? xref.fetchIfRef(option[1]) : option,
|
displayValue: stringToPDFString(isOptionArray ?
|
||||||
|
xref.fetchIfRef(option[1]) : option),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1092,14 +1092,8 @@ describe('annotation', function() {
|
|||||||
|
|
||||||
var options = [['foo_export', 'Foo'], optionOneRef];
|
var options = [['foo_export', 'Foo'], optionOneRef];
|
||||||
var expected = [
|
var expected = [
|
||||||
{
|
{ exportValue: 'foo_export', displayValue: 'Foo', },
|
||||||
exportValue: 'foo_export',
|
{ exportValue: 'bar_export', displayValue: 'Bar', },
|
||||||
displayValue: 'Foo',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
exportValue: 'bar_export',
|
|
||||||
displayValue: 'Bar',
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
choiceWidgetDict.set('Opt', options);
|
choiceWidgetDict.set('Opt', options);
|
||||||
@ -1125,14 +1119,8 @@ describe('annotation', function() {
|
|||||||
|
|
||||||
var options = ['Foo', optionBarRef];
|
var options = ['Foo', optionBarRef];
|
||||||
var expected = [
|
var expected = [
|
||||||
{
|
{ exportValue: 'Foo', displayValue: 'Foo', },
|
||||||
exportValue: 'Foo',
|
{ exportValue: 'Bar', displayValue: 'Bar', },
|
||||||
displayValue: 'Foo',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
exportValue: 'Bar',
|
|
||||||
displayValue: 'Bar',
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
||||||
choiceWidgetDict.set('Opt', options);
|
choiceWidgetDict.set('Opt', options);
|
||||||
@ -1179,6 +1167,31 @@ describe('annotation', function() {
|
|||||||
expect(data.options).toEqual(expected);
|
expect(data.options).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should sanitize display values in option arrays (issue 8947)',
|
||||||
|
function() {
|
||||||
|
// 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.
|
||||||
|
var options = ['\xFE\xFF\x00F\x00o\x00o'];
|
||||||
|
var expected = [
|
||||||
|
{ exportValue: '\xFE\xFF\x00F\x00o\x00o', displayValue: 'Foo', },
|
||||||
|
];
|
||||||
|
|
||||||
|
choiceWidgetDict.set('Opt', options);
|
||||||
|
|
||||||
|
var choiceWidgetRef = new Ref(984, 0);
|
||||||
|
var xref = new XRefMock([
|
||||||
|
{ ref: choiceWidgetRef, data: choiceWidgetDict, },
|
||||||
|
]);
|
||||||
|
|
||||||
|
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
|
||||||
|
pdfManagerMock, idFactoryMock);
|
||||||
|
var data = annotation.data;
|
||||||
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||||
|
|
||||||
|
expect(data.options).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle array field values', function() {
|
it('should handle array field values', function() {
|
||||||
var fieldValue = ['Foo', 'Bar'];
|
var fieldValue = ['Foo', 'Bar'];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user