diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index f3d949e6a..09a7dcd9d 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -53,9 +53,11 @@ function loadAndWait(filename, selector, zoom, setups, options, viewport) { app_options += `&${key}=${encodeURIComponent(value)}`; } } - const url = `${ - global.integrationBaseUrl - }?file=/test/pdfs/${filename}#zoom=${zoom ?? "page-fit"}${app_options}`; + + const fileParam = filename.startsWith("http") + ? filename + : `/test/pdfs/${filename}`; + const url = `${global.integrationBaseUrl}?file=${fileParam}#zoom=${zoom ?? "page-fit"}${app_options}`; if (setups) { // page.evaluateOnNewDocument allows us to run code before the diff --git a/test/integration/viewer_spec.mjs b/test/integration/viewer_spec.mjs index 507d15c41..f2eed67ab 100644 --- a/test/integration/viewer_spec.mjs +++ b/test/integration/viewer_spec.mjs @@ -1244,4 +1244,33 @@ describe("PDF viewer", () => { ); }); }); + + describe("File param with an URL", () => { + let pages; + + beforeEach(async () => { + const baseURL = new URL(global.integrationBaseUrl); + const url = `${baseURL.origin}/build/generic/web/compressed.tracemonkey-pldi-09.pdf`; + pages = await loadAndWait( + encodeURIComponent(url), + ".textLayer .endOfContent" + ); + }); + + afterEach(async () => { + await closePages(pages); + }); + + it("must load and extract the filename correctly", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + const filename = await page.evaluate(() => document.title); + + expect(filename) + .withContext(`In ${browserName}`) + .toBe("compressed.tracemonkey-pldi-09.pdf"); + }) + ); + }); + }); }); diff --git a/web/app.js b/web/app.js index 5978a5afc..bd8cf0068 100644 --- a/web/app.js +++ b/web/app.js @@ -727,7 +727,11 @@ const PDFViewerApplication = { const queryString = document.location.search.substring(1); const params = parseQueryString(queryString); file = params.get("file") ?? AppOptions.get("defaultUrl"); - file = encodeURIComponent(file).replaceAll("%2F", "/"); + try { + file = new URL(decodeURIComponent(file)).href; + } catch { + file = encodeURIComponent(file).replaceAll("%2F", "/"); + } validateFileURL(file); } else if (PDFJSDev.test("MOZCENTRAL")) { file = window.location.href;