LibJS: Stop executing successful regex if it's past the end of the input

If the regex always matches the input, even if it's past the end, then
we need to stop execution of the regex when it's past the end. This
corresponds to step 13.a and prevents it from infinitely looping.

Reduced from: d98672060f/packages/react-i18n/src/utilities/money.ts (L10-L14)
This commit is contained in:
Luke Wilde 2025-02-14 14:55:36 +00:00 committed by Andreas Kling
commit 105096e75a
Notes: github-actions[bot] 2025-02-16 08:23:29 +00:00
2 changed files with 7 additions and 1 deletions

View file

@ -66,3 +66,9 @@ test("Incorrectly escaped code units not converted to invalid patterns", () => {
expect(re.test("⫀")).toBeTrue();
expect(re.test("\\u2abe")).toBeFalse(); // ⫀ is \u2abe
});
test("regexp that always matches stops matching if it's past the end of the string instead of infinitely looping", () => {
const re = new RegExp("[\u200E]*", "gu");
expect("whf".match(re)).toEqual(["", "", "", ""]);
expect(re.lastIndex).toBe(0);
});