1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Build date consistently (in term of tz) when executing some embedded JS (bug 1934157)

The date was create in UTC+0 and then amended in using set-Month/Date which take into account
the user timezone.
With this patch we build all the date in the user timezone.
This commit is contained in:
Calixte Denizet 2024-11-29 17:28:21 +01:00
parent 308ca2a16f
commit 2a337082c0
5 changed files with 76 additions and 22 deletions

View file

@ -2522,4 +2522,42 @@ describe("Interaction", () => {
);
});
});
describe("Date creation must be timezone consistent", () => {
let pages;
beforeAll(async () => {
pages = await loadAndWait("bug1934157.pdf", "[data-annotation-id='24R']");
});
afterAll(async () => {
await closePages(pages);
});
it("must check that date entered by the user is consistent", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
if (browserName === "firefox") {
// Skip the test for Firefox as it doesn't support the timezone
// feature yet with BiDi.
// See https://github.com/puppeteer/puppeteer/issues/13344.
// TODO: Remove this check once the issue is fixed.
return;
}
await waitForScripting(page);
await page.emulateTimezone("Pacific/Honolulu");
const expectedDate = "02/01/2000";
await page.type(getSelector("24R"), expectedDate);
await page.click(getSelector("25R"));
await waitForSandboxTrip(page);
const date = await page.$eval(getSelector("24R"), el => el.value);
expect(date).withContext(`In ${browserName}`).toEqual(expectedDate);
})
);
});
});
});

View file

@ -683,3 +683,4 @@
!issue18956.pdf
!issue19083.pdf
!issue19120.pdf
!bug1934157.pdf

BIN
test/pdfs/bug1934157.pdf Executable file

Binary file not shown.

View file

@ -245,10 +245,10 @@ describe("Scripting", function () {
expect(new Date(value)).toEqual(date);
value = await myeval(`util.scand("mmddyyyy", "07/15/2007").toString()`);
expect(new Date(value)).toEqual(new Date("07/15/2007"));
expect(new Date(value)).toEqual(new Date("07/15/2007 12:00:00"));
value = await myeval(`util.scand("mmddyyyy", "07a15b2007").toString()`);
expect(new Date(value)).toEqual(new Date("07/15/2007"));
expect(new Date(value)).toEqual(new Date("07/15/2007 12:00:00"));
});
});
@ -630,8 +630,9 @@ describe("Scripting", function () {
);
};
await check("05", "dd", "2000/01/05");
await check("12", "mm", "2000/12/01");
const year = new Date().getFullYear();
await check("05", "dd", `${year}/01/05`);
await check("12", "mm", `${year}/12/01`);
await check("2022", "yyyy", "2022/01/01");
await check("a1$9bbbb21", "dd/mm/yyyy", "2021/09/01");
await check("1/2/2024", "dd/mm/yyyy", "2024/02/01");