Merge pull request #15954 from Snuffleupagus/getDocument-URL-tweaks
Tweak the internal handling of the `url`-parameter in `getDocument` (PR 13166 follow-up)
This commit is contained in:
commit
cb5a28ceca
@ -289,18 +289,24 @@ function getDocument(src) {
|
|||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "url":
|
case "url":
|
||||||
if (typeof window !== "undefined") {
|
if (val instanceof URL) {
|
||||||
try {
|
params[key] = val.href;
|
||||||
// The full path is required in the 'url' field.
|
|
||||||
params[key] = new URL(val, window.location).href;
|
|
||||||
continue;
|
|
||||||
} catch (ex) {
|
|
||||||
warn(`Cannot create valid URL: "${ex}".`);
|
|
||||||
}
|
|
||||||
} else if (typeof val === "string" || val instanceof URL) {
|
|
||||||
params[key] = val.toString(); // Support Node.js environments.
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
// The full path is required in the 'url' field.
|
||||||
|
params[key] = new URL(val, window.location).href;
|
||||||
|
continue;
|
||||||
|
} catch (ex) {
|
||||||
|
if (
|
||||||
|
typeof PDFJSDev !== "undefined" &&
|
||||||
|
PDFJSDev.test("GENERIC") &&
|
||||||
|
isNodeJS &&
|
||||||
|
typeof val === "string"
|
||||||
|
) {
|
||||||
|
break; // Use the url as-is in Node.js environments.
|
||||||
|
}
|
||||||
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Invalid PDF url data: " +
|
"Invalid PDF url data: " +
|
||||||
"either string or URL-object is expected in the url property."
|
"either string or URL-object is expected in the url property."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user