Merge pull request #13079 from Snuffleupagus/issue-13075
Ensure that `getDocument` handles Node.js `Buffer`s more gracefully (issue 13075)
This commit is contained in:
commit
ba567321da
@ -243,10 +243,21 @@ function getDocument(src) {
|
|||||||
} else if (key === "worker") {
|
} else if (key === "worker") {
|
||||||
worker = source[key];
|
worker = source[key];
|
||||||
continue;
|
continue;
|
||||||
} else if (key === "data" && !(source[key] instanceof Uint8Array)) {
|
} else if (key === "data") {
|
||||||
// Converting string or array-like data to Uint8Array.
|
// Converting string or array-like data to Uint8Array.
|
||||||
const pdfBytes = source[key];
|
const pdfBytes = source[key];
|
||||||
if (typeof pdfBytes === "string") {
|
if (
|
||||||
|
typeof PDFJSDev !== "undefined" &&
|
||||||
|
PDFJSDev.test("GENERIC") &&
|
||||||
|
isNodeJS &&
|
||||||
|
typeof Buffer !== "undefined" && // eslint-disable-line no-undef
|
||||||
|
pdfBytes instanceof Buffer // eslint-disable-line no-undef
|
||||||
|
) {
|
||||||
|
params[key] = new Uint8Array(pdfBytes);
|
||||||
|
} else if (pdfBytes instanceof Uint8Array) {
|
||||||
|
// Use the data as-is when it's already a Uint8Array.
|
||||||
|
params[key] = pdfBytes;
|
||||||
|
} else if (typeof pdfBytes === "string") {
|
||||||
params[key] = stringToBytes(pdfBytes);
|
params[key] = stringToBytes(pdfBytes);
|
||||||
} else if (
|
} else if (
|
||||||
typeof pdfBytes === "object" &&
|
typeof pdfBytes === "object" &&
|
||||||
@ -259,8 +270,7 @@ function getDocument(src) {
|
|||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Invalid PDF binary data: either typed array, " +
|
"Invalid PDF binary data: either typed array, " +
|
||||||
"string or array-like object is expected in the " +
|
"string, or array-like object is expected in the data property."
|
||||||
"data property."
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user