diff --git a/src/display/content_disposition.js b/src/display/content_disposition.js index 0dec00c88..638e715f2 100644 --- a/src/display/content_disposition.js +++ b/src/display/content_disposition.js @@ -18,8 +18,6 @@ // with the following changes: // - Modified to conform to PDF.js's coding style. // - Support UTF-8 decoding when TextDecoder is unsupported. -// - Replace Array.from with Array + loop for compat with old browsers. -// - Replace "startsWith" with other string method for compat with old browsers. // - Move return to the end of the function to prevent Babel from dropping the // function declarations. @@ -83,10 +81,9 @@ function getFilenameFromContentDispositionHeader(contentDisposition) { } try { let decoder = new TextDecoder(encoding, { fatal: true, }); - let bytes = new Array(value.length); - for (let i = 0; i < value.length; ++i) { - bytes[i] = value.charCodeAt(i); - } + let bytes = Array.from(value, function(ch) { + return ch.charCodeAt(0) & 0xFF; + }); value = decoder.decode(new Uint8Array(bytes)); needsEncodingFixup = false; } catch (e) { @@ -151,7 +148,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) { return parts.join(''); } function rfc2616unquote(value) { - if (value.charAt(0) === '"') { + if (value.startsWith('"')) { let parts = value.slice(1).split('\\"'); // Find the first unescaped " and terminate there. for (let i = 0; i < parts.length; ++i) { @@ -192,7 +189,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) { // Firefox also decodes words even where RFC 2047 section 5 states: // "An 'encoded-word' MUST NOT appear within a 'quoted-string'." - if (value.slice(0, 2) !== '=?' || /[\x00-\x19\x80-\xff]/.test(value)) { + if (!value.startsWith('=?') || /[\x00-\x19\x80-\xff]/.test(value)) { return value; } // RFC 2047, section 2.4 diff --git a/src/shared/compatibility.js b/src/shared/compatibility.js index 53b61cadb..13122af13 100644 --- a/src/shared/compatibility.js +++ b/src/shared/compatibility.js @@ -151,6 +151,15 @@ const hasDOM = typeof window === 'object' && typeof document === 'object'; require('core-js/fn/array/includes'); })(); +// Provides support for Array.from in legacy browsers. +// Support: IE +(function checkArrayFrom() { + if (Array.from) { + return; + } + require('core-js/fn/array/from'); +})(); + // Provides support for Object.assign in legacy browsers. // Support: IE (function checkObjectAssign() {