Merge pull request #21606 from calixteman/fix/ambiguous-date-format

Fix parsing of ambiguous date formats like `Hm`
This commit is contained in:
calixteman 2026-07-20 17:05:01 +02:00 committed by GitHub
commit 997dabf5a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -602,7 +602,11 @@ class Util extends PDFObject {
function (match, patternElement) {
const { pattern, action } = handlers[patternElement];
actions.push(action);
return pattern;
// If the format is "Hm", then /\d{1,2}\d{1,2}/ is ambiguous so we use
// a lookahead to ensure that we match the longest possible sequence.
return pattern.includes(",")
? `(?=${pattern})\\${actions.length}`
: pattern;
}
);

View File

@ -251,6 +251,15 @@ describe("Scripting", function () {
value = await myeval(`util.scand("mmddyyyy", "07a15b2007").toString()`);
expect(new Date(value)).toEqual(new Date("07/15/2007 12:00:00"));
});
it("should handle a format with repeated specifiers", async () => {
const cFormat = "Hm".repeat(40);
const cDate = `${"1".repeat(84)}x`;
const value = await myeval(
`util.scand("${cFormat}", "${cDate}")?.toString() ?? "null"`
);
expect(value).toEqual("null");
});
});
describe("printf", function () {