Add an Array.from polyfill, using core-js, and remove some compatibility hacks from the src/display/content_disposition.js file

This commit is contained in:
Jonas Jenwald 2019-01-20 08:49:20 +01:00
parent 66acc7397f
commit 01d624f6a0
2 changed files with 14 additions and 8 deletions

View File

@ -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

View File

@ -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() {