Simplify the DocumentInfoValidators
definition
With this file now being a proper (ES6) module, it's no longer (technically) necessary for this structure to be lazily initialized. Considering its size, and simplicity, I therefore cannot see the harm in letting `DocumentInfoValidators` just be simple Object instead. While I'm not aware of any bugs caused by the current code, it cannot hurt to add an `isDict` check in `PDFDocument.documentInfo` (since the current code assumes that `infoDict` being defined implies it also being a Dictionary). Finally, the patch also converts a couple of `var` to `let`/`const`.
This commit is contained in:
parent
2d51bce941
commit
8a4466139b
@ -377,22 +377,16 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
return true; /* found */
|
return true; /* found */
|
||||||
}
|
}
|
||||||
|
|
||||||
var DocumentInfoValidators = {
|
const DocumentInfoValidators = {
|
||||||
get entries() {
|
Title: isString,
|
||||||
// Lazily build this since all the validation functions below are not
|
Author: isString,
|
||||||
// defined until after this file loads.
|
Subject: isString,
|
||||||
return shadow(this, 'entries', {
|
Keywords: isString,
|
||||||
Title: isString,
|
Creator: isString,
|
||||||
Author: isString,
|
Producer: isString,
|
||||||
Subject: isString,
|
CreationDate: isString,
|
||||||
Keywords: isString,
|
ModDate: isString,
|
||||||
Creator: isString,
|
Trapped: isName,
|
||||||
Producer: isString,
|
|
||||||
CreationDate: isString,
|
|
||||||
ModDate: isString,
|
|
||||||
Trapped: isName,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
PDFDocument.prototype = {
|
PDFDocument.prototype = {
|
||||||
@ -555,14 +549,13 @@ var PDFDocument = (function PDFDocumentClosure() {
|
|||||||
}
|
}
|
||||||
info('The document information dictionary is invalid.');
|
info('The document information dictionary is invalid.');
|
||||||
}
|
}
|
||||||
if (infoDict) {
|
if (isDict(infoDict)) {
|
||||||
var validEntries = DocumentInfoValidators.entries;
|
|
||||||
// Only fill the document info with valid entries from the spec.
|
// Only fill the document info with valid entries from the spec.
|
||||||
for (var key in validEntries) {
|
for (let key in DocumentInfoValidators) {
|
||||||
if (infoDict.has(key)) {
|
if (infoDict.has(key)) {
|
||||||
var value = infoDict.get(key);
|
const value = infoDict.get(key);
|
||||||
// Make sure the value conforms to the spec.
|
// Make sure the value conforms to the spec.
|
||||||
if (validEntries[key](value)) {
|
if (DocumentInfoValidators[key](value)) {
|
||||||
docInfo[key] = (typeof value !== 'string' ?
|
docInfo[key] = (typeof value !== 'string' ?
|
||||||
value : stringToPDFString(value));
|
value : stringToPDFString(value));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user