Merge pull request #19131 from calixteman/bug1934157
Build date consistently (in term of tz) when executing some embedded JS (bug 1934157)
This commit is contained in:
commit
8f08ca2150
@ -349,53 +349,53 @@ class Util extends PDFObject {
|
|||||||
this.#dateActionsCache.set(cFormat, actions);
|
this.#dateActionsCache.set(cFormat, actions);
|
||||||
cFormat.replaceAll(
|
cFormat.replaceAll(
|
||||||
/(d+)|(m+)|(y+)|(H+)|(M+)|(s+)/g,
|
/(d+)|(m+)|(y+)|(H+)|(M+)|(s+)/g,
|
||||||
function (match, d, m, y, H, M, s) {
|
function (_match, d, m, y, H, M, s) {
|
||||||
if (d) {
|
if (d) {
|
||||||
actions.push((n, date) => {
|
actions.push((n, data) => {
|
||||||
if (n >= 1 && n <= 31) {
|
if (n >= 1 && n <= 31) {
|
||||||
date.setDate(n);
|
data.day = n;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
} else if (m) {
|
} else if (m) {
|
||||||
actions.push((n, date) => {
|
actions.push((n, data) => {
|
||||||
if (n >= 1 && n <= 12) {
|
if (n >= 1 && n <= 12) {
|
||||||
date.setMonth(n - 1);
|
data.month = n - 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
} else if (y) {
|
} else if (y) {
|
||||||
actions.push((n, date) => {
|
actions.push((n, data) => {
|
||||||
if (n < 50) {
|
if (n < 50) {
|
||||||
n += 2000;
|
n += 2000;
|
||||||
} else if (n < 100) {
|
} else if (n < 100) {
|
||||||
n += 1900;
|
n += 1900;
|
||||||
}
|
}
|
||||||
date.setYear(n);
|
data.year = n;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
} else if (H) {
|
} else if (H) {
|
||||||
actions.push((n, date) => {
|
actions.push((n, data) => {
|
||||||
if (n >= 0 && n <= 23) {
|
if (n >= 0 && n <= 23) {
|
||||||
date.setHours(n);
|
data.hours = n;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
} else if (M) {
|
} else if (M) {
|
||||||
actions.push((n, date) => {
|
actions.push((n, data) => {
|
||||||
if (n >= 0 && n <= 59) {
|
if (n >= 0 && n <= 59) {
|
||||||
date.setMinutes(n);
|
data.minutes = n;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
} else if (s) {
|
} else if (s) {
|
||||||
actions.push((n, date) => {
|
actions.push((n, data) => {
|
||||||
if (n >= 0 && n <= 59) {
|
if (n >= 0 && n <= 59) {
|
||||||
date.setSeconds(n);
|
data.seconds = n;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -409,10 +409,17 @@ class Util extends PDFObject {
|
|||||||
const number = /\d+/g;
|
const number = /\d+/g;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
let array;
|
let array;
|
||||||
const date = new Date(0);
|
const data = {
|
||||||
|
year: new Date().getFullYear(),
|
||||||
|
month: 0,
|
||||||
|
day: 1,
|
||||||
|
hours: 12,
|
||||||
|
minutes: 0,
|
||||||
|
seconds: 0,
|
||||||
|
};
|
||||||
while ((array = number.exec(cDate)) !== null) {
|
while ((array = number.exec(cDate)) !== null) {
|
||||||
if (i < actions.length) {
|
if (i < actions.length) {
|
||||||
if (!actions[i++](parseInt(array[0]), date)) {
|
if (!actions[i++](parseInt(array[0]), data)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -424,7 +431,14 @@ class Util extends PDFObject {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return date;
|
return new Date(
|
||||||
|
data.year,
|
||||||
|
data.month,
|
||||||
|
data.day,
|
||||||
|
data.hours,
|
||||||
|
data.minutes,
|
||||||
|
data.seconds
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
scand(cFormat, cDate) {
|
scand(cFormat, cDate) {
|
||||||
@ -605,10 +619,10 @@ class Util extends PDFObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
year: 2000,
|
year: new Date().getFullYear(),
|
||||||
month: 0,
|
month: 0,
|
||||||
day: 1,
|
day: 1,
|
||||||
hours: 0,
|
hours: 12,
|
||||||
minutes: 0,
|
minutes: 0,
|
||||||
seconds: 0,
|
seconds: 0,
|
||||||
am: null,
|
am: null,
|
||||||
|
|||||||
@ -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);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -683,3 +683,4 @@
|
|||||||
!issue18956.pdf
|
!issue18956.pdf
|
||||||
!issue19083.pdf
|
!issue19083.pdf
|
||||||
!issue19120.pdf
|
!issue19120.pdf
|
||||||
|
!bug1934157.pdf
|
||||||
|
|||||||
BIN
test/pdfs/bug1934157.pdf
Executable file
BIN
test/pdfs/bug1934157.pdf
Executable file
Binary file not shown.
@ -245,10 +245,10 @@ describe("Scripting", function () {
|
|||||||
expect(new Date(value)).toEqual(date);
|
expect(new Date(value)).toEqual(date);
|
||||||
|
|
||||||
value = await myeval(`util.scand("mmddyyyy", "07/15/2007").toString()`);
|
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()`);
|
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");
|
const year = new Date().getFullYear();
|
||||||
await check("12", "mm", "2000/12/01");
|
await check("05", "dd", `${year}/01/05`);
|
||||||
|
await check("12", "mm", `${year}/12/01`);
|
||||||
await check("2022", "yyyy", "2022/01/01");
|
await check("2022", "yyyy", "2022/01/01");
|
||||||
await check("a1$9bbbb21", "dd/mm/yyyy", "2021/09/01");
|
await check("a1$9bbbb21", "dd/mm/yyyy", "2021/09/01");
|
||||||
await check("1/2/2024", "dd/mm/yyyy", "2024/02/01");
|
await check("1/2/2024", "dd/mm/yyyy", "2024/02/01");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user