Only warn about unsupported JavaScript, in the viewer, when non-empty actions exist (issue 5767)

Some PDF files contain JavaScript actions that consist of nothing more that one, or possibly several, empty string(s). At least to me, printing a warning/showing the fallback seems completely unnecessary in that case.

Furthermore, this patch also makes use of an early `return`, so that we no longer will attempt to check for printing instructions when no JavaScript is present in the PDF file.

*Note:* It would perhaps make sense to change the API/core code, such that we ignore empty entries there instead. However, that would probably be considered a breaking changing with respect to backwards compatibility, hence this simple viewer only solution.

Fixes 5767.
This commit is contained in:
Jonas Jenwald 2017-10-08 14:06:33 +02:00
parent ab4d5be192
commit b5a044b931

View File

@ -1047,10 +1047,18 @@ let PDFViewerApplication = {
return;
}
pdfDocument.getJavaScript().then((javaScript) => {
if (javaScript.length) {
if (javaScript.length === 0) {
return;
}
javaScript.some((js) => {
if (!js) { // Don't warn/fallback for empty JavaScript actions.
return false;
}
console.warn('Warning: JavaScript is not supported');
this.fallback(UNSUPPORTED_FEATURES.javaScript);
}
return true;
});
// Hack to support auto printing.
let regex = /\bprint\s*\(/;
for (let i = 0, ii = javaScript.length; i < ii; i++) {