Skip to content

Handle out-of-range Unicode escapes as parse errors - #5710

Merged
rmosolgo merged 1 commit into
rmosolgo:masterfrom
ydah:reject-out-of-range-unicode-escapes
Aug 27, 2026
Merged

Handle out-of-range Unicode escapes as parse errors#5710
rmosolgo merged 1 commit into
rmosolgo:masterfrom
ydah:reject-out-of-range-unicode-escapes

Conversation

@ydah

@ydah ydah commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

An out-of-range Unicode escape currently causes GraphQL::Language::Lexer to raise a raw RangeError:

MySchema.execute('{ echo(input: "\\u{FFFFFFFFFF}") }')
# RangeError: pack(U): value out of range

This happens when replace_escaped_characters_in_place passes the decoded codepoint to Array#pack("U"). Since the exception bypasses GraphQL's parse error handling, applications may return an HTTP 500 for an invalid query.

This PR catches that RangeError and reports it through the lexer's existing raise_parse_error path. The same query is now returned as a normal GraphQL parse error.

A regression test covers Unicode escapes above the valid codepoint range.

@rmosolgo

Copy link
Copy Markdown
Owner

Cool, thanks 👍

@rmosolgo
rmosolgo merged commit 8a1a9e4 into rmosolgo:master Aug 27, 2026
14 of 15 checks passed
@rmosolgo rmosolgo added this to the 2.6.10 milestone Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants