Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions test/integration/viewer_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,40 @@ describe("PDF viewer", () => {
});
});

describe("File param with encoded characters (issue 20420)", () => {
let pages;

beforeEach(async () => {
const baseURL = new URL(global.integrationBaseUrl);
const url = `${baseURL.origin}/build/generic/web/compressed.tracemonkey-pldi-09.pdf?token=%2Ffoo`;
pages = await loadAndWait(
encodeURIComponent(url),
".textLayer .endOfContent"
);
});

afterEach(async () => {
await closePages(pages);
});

it("must not double-decode the file param", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const pdfUrl = await page.evaluate(
() => window.PDFViewerApplication.url
);

expect(pdfUrl)
.withContext(`In ${browserName}`)
.toContain("token=%2Ffoo");
expect(pdfUrl)
.withContext(`In ${browserName}`)
.not.toContain("token=/foo");
})
);
});
});

describe("Keyboard scrolling on startup (bug 843653)", () => {
let pages;

Expand Down
2 changes: 1 addition & 1 deletion web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ const PDFViewerApplication = {
const params = parseQueryString(queryString);
file = params.get("file") ?? AppOptions.get("defaultUrl");
try {
file = new URL(decodeURIComponent(file)).href;
file = new URL(file).href;
} catch {
file = encodeURIComponent(file).replaceAll("%2F", "/");
}
Expand Down