Skip to content

Commit a254485

Browse files
Fix #20420: Prevent double decoding of file URL parameter
1 parent 615965f commit a254485

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

test/integration/viewer_spec.mjs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,40 @@ describe("PDF viewer", () => {
12601260
});
12611261
});
12621262

1263+
describe("File param with encoded characters (issue 20420)", () => {
1264+
let pages;
1265+
1266+
beforeEach(async () => {
1267+
const baseURL = new URL(global.integrationBaseUrl);
1268+
const url = `${baseURL.origin}/build/generic/web/compressed.tracemonkey-pldi-09.pdf?token=%2Ffoo`;
1269+
pages = await loadAndWait(
1270+
encodeURIComponent(url),
1271+
".textLayer .endOfContent"
1272+
);
1273+
});
1274+
1275+
afterEach(async () => {
1276+
await closePages(pages);
1277+
});
1278+
1279+
it("must not double-decode the file param", async () => {
1280+
await Promise.all(
1281+
pages.map(async ([browserName, page]) => {
1282+
const pdfUrl = await page.evaluate(
1283+
() => window.PDFViewerApplication.url
1284+
);
1285+
1286+
expect(pdfUrl)
1287+
.withContext(`In ${browserName}`)
1288+
.toContain("token=%2Ffoo");
1289+
expect(pdfUrl)
1290+
.withContext(`In ${browserName}`)
1291+
.not.toContain("token=/foo");
1292+
})
1293+
);
1294+
});
1295+
});
1296+
12631297
describe("Keyboard scrolling on startup (bug 843653)", () => {
12641298
let pages;
12651299

web/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ const PDFViewerApplication = {
789789
const params = parseQueryString(queryString);
790790
file = params.get("file") ?? AppOptions.get("defaultUrl");
791791
try {
792-
file = new URL(decodeURIComponent(file)).href;
792+
file = new URL(file).href;
793793
} catch {
794794
file = encodeURIComponent(file).replaceAll("%2F", "/");
795795
}

0 commit comments

Comments
 (0)