Skip to content

fix(parser): recover from out-of-range \u{...} code points - #18580

Merged
JLHwung merged 1 commit into
mainfrom
jlhwung/fix-parser-recovery-invalid-code-point
Nov 11, 2026
Merged

JLHwung merged 1 commit into
mainfrom
jlhwung/fix-parser-recovery-invalid-code-point

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 11, 2026

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? When errorRecovery: true, Babel parser crashes on invalid input \u{110000}
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

In this PR we fix an issue reported by Claude Fable: When errorRecovery is true, the invalid codepoint 110000 was sent to String.fromCodePoint which crashed the parser. In this PR we always return { code: null } in readCodePoint so the current parser logic can handle and recover from invalid codepoints.

With `errorRecovery: true`, `parse("\\u{110000}")`, `parse('"\\u{110000}"')`,
`#\u{110000}` private names and huge values like `"\u{FFFFFFFFFFFFFFFFF}"`
crashed with `RangeError: Invalid code point 1114112` from
`String.fromCodePoint`. `readCodePoint` reported `InvalidCodePoint` (which only
records the error in recovery mode) but still returned the out-of-range code
to its callers. Return `code: null` instead, like the `throwOnInvalid: false`
branch, so the escape is dropped the same way as other invalid escapes and
the proper `InvalidCodePoint` error is recorded (or thrown without recovery).

Assisted-by: Claude Fable 5.1 <[email protected]>
@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories pkg: parser 7.x: needs backport labels Nov 11, 2026
@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63169

@pkg-pr-new

pkg-pr-new Bot commented Nov 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: 4ddc0d9

@JLHwung
JLHwung added this pull request to the merge queue Nov 11, 2026
Merged via the queue into main with commit f516b69 Nov 11, 2026
67 checks passed
@JLHwung
JLHwung deleted the jlhwung/fix-parser-recovery-invalid-code-point branch November 11, 2026 16:46
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18591.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants