From b5a044b931f567d0e7441d28381d4a72ba9e049d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 8 Oct 2017 14:06:33 +0200 Subject: [PATCH] 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. --- web/app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/app.js b/web/app.js index ed5e6fbe2..786d4b9ca 100644 --- a/web/app.js +++ b/web/app.js @@ -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++) {