mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Text widget annotations: implement unit testing and sanitize data values
This commit is contained in:
parent
4d1592883d
commit
323e86c442
3 changed files with 71 additions and 5 deletions
|
@ -671,8 +671,19 @@ var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
|
|||
function TextWidgetAnnotation(params) {
|
||||
WidgetAnnotation.call(this, params);
|
||||
|
||||
this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
|
||||
this.data.maxLen = Util.getInheritableProperty(params.dict, 'MaxLen');
|
||||
// Determine the alignment of text in the field.
|
||||
var alignment = Util.getInheritableProperty(params.dict, 'Q');
|
||||
if (!isInt(alignment) || alignment < 0 || alignment > 2) {
|
||||
alignment = null;
|
||||
}
|
||||
this.data.textAlignment = alignment;
|
||||
|
||||
// Determine the maximum length of text in the field.
|
||||
var maximumLength = Util.getInheritableProperty(params.dict, 'MaxLen');
|
||||
if (!isInt(maximumLength) || maximumLength < 0) {
|
||||
maximumLength = null;
|
||||
}
|
||||
this.data.maxLen = maximumLength;
|
||||
}
|
||||
|
||||
Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
||||
var AnnotationType = sharedUtil.AnnotationType;
|
||||
var isInt = sharedUtil.isInt;
|
||||
var Util = sharedUtil.Util;
|
||||
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
||||
var LinkTarget = displayDOMUtils.LinkTarget;
|
||||
|
@ -451,7 +450,7 @@ var TextWidgetAnnotationElement = (
|
|||
element.type = 'text';
|
||||
element.value = this.data.fieldValue;
|
||||
|
||||
if (isInt(this.data.maxLen)) {
|
||||
if (this.data.maxLen !== null) {
|
||||
element.maxLength = this.data.maxLen;
|
||||
}
|
||||
} else {
|
||||
|
@ -467,7 +466,7 @@ var TextWidgetAnnotationElement = (
|
|||
this._setTextStyle(element, font);
|
||||
}
|
||||
|
||||
if (isInt(this.data.textAlignment)) {
|
||||
if (this.data.textAlignment !== null) {
|
||||
element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue