Merge pull request #10473 from Snuffleupagus/array-from
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:
commit
78eb73004f
@ -18,8 +18,6 @@
|
|||||||
// with the following changes:
|
// with the following changes:
|
||||||
// - Modified to conform to PDF.js's coding style.
|
// - Modified to conform to PDF.js's coding style.
|
||||||
// - Support UTF-8 decoding when TextDecoder is unsupported.
|
// - 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
|
// - Move return to the end of the function to prevent Babel from dropping the
|
||||||
// function declarations.
|
// function declarations.
|
||||||
|
|
||||||
@ -83,10 +81,9 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let decoder = new TextDecoder(encoding, { fatal: true, });
|
let decoder = new TextDecoder(encoding, { fatal: true, });
|
||||||
let bytes = new Array(value.length);
|
let bytes = Array.from(value, function(ch) {
|
||||||
for (let i = 0; i < value.length; ++i) {
|
return ch.charCodeAt(0) & 0xFF;
|
||||||
bytes[i] = value.charCodeAt(i);
|
});
|
||||||
}
|
|
||||||
value = decoder.decode(new Uint8Array(bytes));
|
value = decoder.decode(new Uint8Array(bytes));
|
||||||
needsEncodingFixup = false;
|
needsEncodingFixup = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -151,7 +148,7 @@ function getFilenameFromContentDispositionHeader(contentDisposition) {
|
|||||||
return parts.join('');
|
return parts.join('');
|
||||||
}
|
}
|
||||||
function rfc2616unquote(value) {
|
function rfc2616unquote(value) {
|
||||||
if (value.charAt(0) === '"') {
|
if (value.startsWith('"')) {
|
||||||
let parts = value.slice(1).split('\\"');
|
let parts = value.slice(1).split('\\"');
|
||||||
// Find the first unescaped " and terminate there.
|
// Find the first unescaped " and terminate there.
|
||||||
for (let i = 0; i < parts.length; ++i) {
|
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:
|
// Firefox also decodes words even where RFC 2047 section 5 states:
|
||||||
// "An 'encoded-word' MUST NOT appear within a 'quoted-string'."
|
// "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;
|
return value;
|
||||||
}
|
}
|
||||||
// RFC 2047, section 2.4
|
// RFC 2047, section 2.4
|
||||||
|
@ -151,6 +151,15 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
|
|||||||
require('core-js/fn/array/includes');
|
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.
|
// Provides support for Object.assign in legacy browsers.
|
||||||
// Support: IE
|
// Support: IE
|
||||||
(function checkObjectAssign() {
|
(function checkObjectAssign() {
|
||||||
|
Loading…
Reference in New Issue
Block a user