Sanitize the display value for choice widget annotations

This commit is contained in:
Tim van der Meij 2017-11-18 16:47:32 +01:00
parent 9e8cf448b0
commit 25b07812b9
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762
2 changed files with 31 additions and 17 deletions

View File

@ -798,7 +798,8 @@ class ChoiceWidgetAnnotation extends WidgetAnnotation {
this.data.options[i] = {
exportValue: isOptionArray ? xref.fetchIfRef(option[0]) : option,
displayValue: isOptionArray ? xref.fetchIfRef(option[1]) : option,
displayValue: stringToPDFString(isOptionArray ?
xref.fetchIfRef(option[1]) : option),
};
}
}

View File

@ -1092,14 +1092,8 @@ describe('annotation', function() {
var options = [['foo_export', 'Foo'], optionOneRef];
var expected = [
{
exportValue: 'foo_export',
displayValue: 'Foo',
},
{
exportValue: 'bar_export',
displayValue: 'Bar',
}
{ exportValue: 'foo_export', displayValue: 'Foo', },
{ exportValue: 'bar_export', displayValue: 'Bar', },
];
choiceWidgetDict.set('Opt', options);
@ -1125,14 +1119,8 @@ describe('annotation', function() {
var options = ['Foo', optionBarRef];
var expected = [
{
exportValue: 'Foo',
displayValue: 'Foo',
},
{
exportValue: 'Bar',
displayValue: 'Bar',
}
{ exportValue: 'Foo', displayValue: 'Foo', },
{ exportValue: 'Bar', displayValue: 'Bar', },
];
choiceWidgetDict.set('Opt', options);
@ -1179,6 +1167,31 @@ describe('annotation', function() {
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() {
var fieldValue = ['Foo', 'Bar'];