mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-03 05:35:49 +02:00
Merge pull request #20482 from Uzair-Ahmed-Shah/fix-issue-20420
Fix #20420: Prevent double decoding of file URL parameter
This commit is contained in:
commit
8b4fae0a84
@ -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)", () => {
|
describe("Keyboard scrolling on startup (bug 843653)", () => {
|
||||||
let pages;
|
let pages;
|
||||||
|
|
||||||
|
|||||||
@ -789,7 +789,7 @@ const PDFViewerApplication = {
|
|||||||
const params = parseQueryString(queryString);
|
const params = parseQueryString(queryString);
|
||||||
file = params.get("file") ?? AppOptions.get("defaultUrl");
|
file = params.get("file") ?? AppOptions.get("defaultUrl");
|
||||||
try {
|
try {
|
||||||
file = new URL(decodeURIComponent(file)).href;
|
file = new URL(file).href;
|
||||||
} catch {
|
} catch {
|
||||||
file = encodeURIComponent(file).replaceAll("%2F", "/");
|
file = encodeURIComponent(file).replaceAll("%2F", "/");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user