Skip to content

Reject invalid Unicode escapes in UTF-16 and UTF-32 regexps - #10121

Draft
headius wants to merge 1 commit into
jruby:jruby-10.0from
headius:codex/regexp-invalid-codepoint-jr10
Draft

headius wants to merge 1 commit into
jruby:jruby-10.0from
headius:codex/regexp-invalid-codepoint-jr10

Conversation

@headius

@headius headius commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

JRuby can pass invalid \x{...} code point escapes in UTF-16 and UTF-32 regexps to Joni. With Joni 2.2.10, a short invalid escape such as \x{D801} encoded as UTF-16LE remains in compilation and loops in OptExactInfo.concatStr instead of raising. This validates Unicode scalar values before compilation and raises the existing RegexpError for surrogate and out-of-range values. Valid supplementary code points still compile and match.

The regression covers the invalid and valid UTF-16/32 cases added in CRuby PR #20002, including the upstream test.

Joni remains the engine-level failure point: its optimizer should also avoid looping when an encoding reports a zero-length character. This JRuby change rejects the invalid scalar before handing it to Joni; it does not change Joni itself.

Verification

  • Java 21 build: PATH="$JAVA_HOME/bin:$PATH" ./mvnw -q -o -DskipTests -pl core,shaded package
  • PATH="$JAVA_HOME/bin:$PATH" bin/jruby spec/mspec/bin/mspec-run spec/ruby/core/regexp/encoding_spec.rb — 14 examples, 42 expectations, 0 failures/errors.
  • Ran the bounded invalid/valid escape matrix for UTF-16LE/BE and UTF-32LE/BE after the build. All invalid scalar escapes raised RegexpError; valid U+1F600 patterns matched.
  • No system CRuby executable was available for a local spec run.

@headius headius changed the title Reject invalid Unicode escapes in UTF-16 regexps Reject invalid Unicode escapes in UTF-16 and UTF-32 regexps Nov 19, 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.

1 participant