-
Notifications
You must be signed in to change notification settings - Fork 5.1k
RegExp: reject \ + non-ASCII identity escapes with the u and v flags (WebKit bump for oven-sh/WebKit#577) #41767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
13
commits into
main
Choose a base branch
from
robobun/17f7b53d/regexp-astral-escape
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−1
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8841f6e
WebKit 1de631c31f79: RegExp.escape narrows supplementary code points,…
robobun 991763d
test: bound the supplementary sweep so the debug build stays under th…
robobun 95c9789
WebKit e11053bf2cd5: bound the JSTests sweep (oven-sh/WebKit#577 head)
robobun 983aac7
test: use test.each for the parameterized RegExp escape cases
robobun 256b555
Merge branch 'main' into robobun/17f7b53d/regexp-astral-escape
Jarred-Sumner 8ed649b
WebKit: pin the oven-sh/WebKit#577 preview tag now that main download…
robobun 64bd196
Merge remote-tracking branch 'origin/main' into robobun/17f7b53d/rege…
robobun 0c280a1
Merge remote-tracking branch 'origin/main' into robobun/17f7b53d/rege…
robobun aa8a079
Merge remote-tracking branch 'origin/main' into robobun/17f7b53d/rege…
robobun 44b1023
Merge remote-tracking branch 'origin/main' into robobun/17f7b53d/rege…
robobun 6b0eb23
Merge remote-tracking branch 'origin/main' into robobun/17f7b53d/rege…
robobun e2c4ac3
Merge remote-tracking branch 'origin/main' into robobun/17f7b53d/rege…
robobun 892bf9c
test: add the NUL, ASCII, literal and unicode-escape controls from #4…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
|
|
||
| // Coverage for oven-sh/WebKit#577. RegExp.escape classified a supplementary | ||
| // code point by its low 16 bits, and Yarr accepted "\" + any non-ASCII | ||
| // character as an identity escape in Unicode mode. | ||
|
|
||
| describe("RegExp.escape with supplementary code points", () => { | ||
| // Each low 16-bit value below is a character RegExp.escape has to escape | ||
| // when it stands alone. The full code point is not that character. | ||
| test.each([ | ||
| { codePoint: "2002A", lowBits: "'*'" }, | ||
| { codePoint: "20009", lowBits: "tab" }, | ||
| { codePoint: "2002C", lowBits: "','" }, | ||
| { codePoint: "20020", lowBits: "space" }, | ||
| { codePoint: "12000", lowBits: "U+2000" }, | ||
| { codePoint: "1FEFF", lowBits: "U+FEFF" }, | ||
| ])("U+$codePoint (low 16 bits: $lowBits) passes through unchanged", ({ codePoint }) => { | ||
| const s = String.fromCodePoint(parseInt(codePoint, 16)); | ||
| expect(RegExp.escape(s)).toBe(s); | ||
| for (const flags of ["", "u", "v"]) { | ||
| expect(new RegExp(RegExp.escape(s), flags).test(s)).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| test("escaped CJK Extension B text matches itself under u and v", () => { | ||
| const name = "陳\u{2002A}文"; | ||
| const hay = `abc ${name} xyz`; | ||
| expect(hay.search(new RegExp(RegExp.escape(name), "v"))).toBe(4); | ||
| expect(hay.replaceAll(new RegExp(RegExp.escape(name), "gu"), "#")).toBe("abc # xyz"); | ||
| }); | ||
|
|
||
| test("no supplementary code point is escaped, in any plane", () => { | ||
| // Every BMP code unit that RegExp.escape rewrites: SyntaxCharacter, '/', | ||
| // the other punctuators, ControlEscape, WhiteSpace, LineTerminator, and a | ||
| // sample of the surrogate range. A supplementary code point with these | ||
| // low 16 bits is an ordinary character. | ||
| const escapedLow16 = [ | ||
| ..."^$\\.*+?()[]{}|/,-=<>#&!%:;@~'`\"\t\n\v\f\r \u00a0\u1680\u2028\u2029\u202f\u205f\u3000\ufeff", | ||
| ].map(c => c.charCodeAt(0)); | ||
| for (let c = 0x2000; c <= 0x200a; c++) escapedLow16.push(c); | ||
| escapedLow16.push(0xd800, 0xd83d, 0xdbff, 0xdc00, 0xde00, 0xdfff); | ||
| for (const low of escapedLow16) { | ||
| expect(RegExp.escape("_" + String.fromCharCode(low))).not.toBe("_" + String.fromCharCode(low)); | ||
| } | ||
|
|
||
| const changed: string[] = []; | ||
| for (let plane = 1; plane <= 16; plane++) { | ||
| for (const low of escapedLow16) { | ||
| const cp = (plane << 16) | low; | ||
| const s = String.fromCodePoint(cp); | ||
| if (RegExp.escape(s) !== s) changed.push("U+" + cp.toString(16)); | ||
| } | ||
| } | ||
| for (let cp = 0x10000; cp < 0x110000; cp += 331) { | ||
| const s = String.fromCodePoint(cp); | ||
| if (RegExp.escape(s) !== s) changed.push("U+" + cp.toString(16)); | ||
| } | ||
| expect(changed).toEqual([]); | ||
| }); | ||
|
|
||
| test("BMP inputs are still escaped", () => { | ||
| expect(RegExp.escape("^$\\.*+?()[]{}|/")).toBe("\\^\\$\\\\\\.\\*\\+\\?\\(\\)\\[\\]\\{\\}\\|\\/"); | ||
| expect(RegExp.escape(",-=<>#&!%:;@~'`\"")).toBe( | ||
| "\\x2c\\x2d\\x3d\\x3c\\x3e\\x23\\x26\\x21\\x25\\x3a\\x3b\\x40\\x7e\\x27\\x60\\x22", | ||
| ); | ||
| expect(RegExp.escape("\t\n\v\f\r")).toBe("\\t\\n\\v\\f\\r"); | ||
| expect(RegExp.escape(" \uFEFF\u2000\u3000")).toBe("\\x20\\ufeff\\u2000\\u3000"); | ||
| expect(RegExp.escape("\uD800_\uDFFF")).toBe("\\ud800_\\udfff"); | ||
| expect(RegExp.escape("test")).toBe("\\x74est"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("identity escapes in Unicode mode", () => { | ||
| // BMP letters, supplementary characters, each lone surrogate half, a | ||
| // LineTerminator and U+FEFF: none of these is a SyntaxCharacter or '/'. | ||
| test.each(["00E9", "00C7", "4E2D", "5B57", "1F600", "1D4B3", "D83D", "DE00", "2028", "FEFF"])( | ||
| '"\\\\" + U+%s is a SyntaxError with the u and v flags', | ||
| codePoint => { | ||
| const ch = String.fromCodePoint(parseInt(codePoint, 16)); | ||
| for (const flags of ["u", "v"]) { | ||
| expect(() => new RegExp("\\" + ch, flags)).toThrow(SyntaxError); | ||
| expect(() => new RegExp("[\\" + ch + "]", flags)).toThrow(SyntaxError); | ||
| expect(() => new RegExp("(?:\\" + ch + ")+", flags)).toThrow(SyntaxError); | ||
| } | ||
| expect(() => new RegExp("[\\q{\\" + ch + "}]", "v")).toThrow(SyntaxError); | ||
| expect(() => new RegExp("[[a]--[\\" + ch + "]]", "v")).toThrow(SyntaxError); | ||
| }, | ||
| ); | ||
|
|
||
| test("SyntaxCharacter and '/' are still identity escapes", () => { | ||
| for (const ch of "^$\\.*+?()[]{}|/") { | ||
| for (const flags of ["u", "v"]) { | ||
| expect(new RegExp("^\\" + ch + "$", flags).test(ch)).toBe(true); | ||
| } | ||
| } | ||
| expect(/^[\-]$/u.test("-")).toBe(true); | ||
| expect(/^[\]]$/u.test("]")).toBe(true); | ||
| expect(/^[\&]$/v.test("&")).toBe(true); | ||
| }); | ||
|
|
||
| test("NUL and ASCII characters outside the allowed set are still a SyntaxError", () => { | ||
| for (const flags of ["u", "v"]) { | ||
| expect(() => new RegExp("\\\u0000", flags)).toThrow(SyntaxError); | ||
| expect(() => new RegExp("\\a", flags)).toThrow(SyntaxError); | ||
| expect(() => new RegExp("\\q", flags)).toThrow(SyntaxError); | ||
| expect(() => new RegExp("\\ ", flags)).toThrow(SyntaxError); | ||
| } | ||
| }); | ||
|
|
||
| test("an unescaped or unicode-escaped non-ASCII character still matches with u and v", () => { | ||
| for (const flags of ["u", "v"]) { | ||
| expect(new RegExp("^\u00c7$", flags).test("\u00c7")).toBe(true); | ||
| expect(new RegExp("^\\u00C7$", flags).test("\u00c7")).toBe(true); | ||
| expect(new RegExp("^\\u{1D4B3}$", flags).test("\u{1D4B3}")).toBe(true); | ||
| expect(new RegExp("^[\u{1D4B3}]$", flags).test("\u{1D4B3}")).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| test("non-Unicode patterns keep the Annex B identity escape", () => { | ||
| for (const ch of ["\u00e9", "\u00c7", "\u4e2d", "\u{1F600}"]) { | ||
| expect(new RegExp("^\\" + ch + "$").test(ch)).toBe(true); | ||
| expect(new RegExp("^[\\" + ch + "]+$").test(ch)).toBe(true); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Update the pin after WebKit
#577merges.WEBKIT_VERSIONpoints to a prerelease tag. (github.com) WebKit#577remains open as of September 24, 2026. (github.com) Before merging this Bun change, wait for#577to merge, then pin its merge release’sautobuild-<sha>tag unless Bun’s current WebKit pin already includes the fix. Otherwise, the merged build remains tied to an unmerged preview.This is the merge prerequisite stated in the PR objective.
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, and this is the merge prerequisite in the PR body. After oven-sh/WebKit#577 merges, the pin moves to the
autobuild-<sha>release of its merge commit. If the WebKit pin onmainalready contains that commit by then, I drop the pin change and the PR is the test only. I leave this thread open until then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robobun, thanks for clarifying. The PR body already states this merge prerequisite. Keep this thread open until WebKit#577merges and the preview pin is replaced or removed.🧠 Learnings used
You are interacting with an AI system.