Tweak the internal handling of the url-parameter in getDocument (PR 13166 follow-up)

- Use a `URL`-instance directly, since it's by definition an absolute URL.
 - Actually limit the "raw" url-string handling to Node.js environments, as intended.
 - Skip the warning, since we're already throwing an Error if the `url`-parameter is invalid.
This commit is contained in:
Jonas Jenwald 2023-01-24 10:40:45 +01:00
parent 673f6820d1
commit 755319130e

View File

@ -289,17 +289,23 @@ function getDocument(src) {
switch (key) { switch (key) {
case "url": case "url":
if (typeof window !== "undefined") { if (val instanceof URL) {
params[key] = val.href;
continue;
}
try { try {
// The full path is required in the 'url' field. // The full path is required in the 'url' field.
params[key] = new URL(val, window.location).href; params[key] = new URL(val, window.location).href;
continue; continue;
} catch (ex) { } catch (ex) {
warn(`Cannot create valid URL: "${ex}".`); if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC") &&
isNodeJS &&
typeof val === "string"
) {
break; // Use the url as-is in Node.js environments.
} }
} else if (typeof val === "string" || val instanceof URL) {
params[key] = val.toString(); // Support Node.js environments.
continue;
} }
throw new Error( throw new Error(
"Invalid PDF url data: " + "Invalid PDF url data: " +