Skip to content

mruby-regexp: ask the malformed sequence cases of a byte-indexed subject too - #7116

Merged
matz merged 1 commit into
mruby:masterfrom
takumin:regexp-malformed-byte-indexed-tests
Aug 12, 2026
Merged

mruby-regexp: ask the malformed sequence cases of a byte-indexed subject too#7116
matz merged 1 commit into
mruby:masterfrom
takumin:regexp-malformed-byte-indexed-tests

Conversation

@takumin

@takumin takumin commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Split out of #7110, which asked for one review of a behaviour change and a
large test rewrite at once. This is the second of four pieces, independent of
the first, and changes no behaviour.

Three cases turn on what a malformed sequence is rather than on how the subject
is indexed:

  • whether an overlong sequence, a surrogate or a codepoint above U+10FFFF is the
    character it spells
  • whether a lone leader at the end of the subject sends the walk past the string
    buffer
  • whether a truncated leader in a character class sends it past the pattern
    buffer

Each is asked through a UTF-8 subject only.

Why that is a different question to ask

The engine reads a byte-indexed subject through a branch of its own:
mrb_re_charlen() and mrb_re_decode_char() take a flag for one and hand back a
byte at a time. So the walk that must stay inside the buffer at the end of
"ab\xf0" is a different walk there, and the decode that must not turn C0 BC
into < is a different decode. The last two cases came from fuzzing, so the
walk is worth pinning on both sides.

What this does

Asks each of them on that side as well, next to the case it answers.

Verified

  • rake test on a full-core build (MRB_UTF8_STRING through mruby-encoding):
    2249 tests, all green
  • rake test on the default gembox (no MRB_UTF8_STRING): 2058 tests, all
    green
  • prek run --all-files passes, except that markdownlint could not install
    locally (npm engine mismatch); no Markdown is touched here

Summary by CodeRabbit

  • Bug Fixes
    • Improved regular expression handling for truncated or invalid UTF-8 sequences.
    • Ensured consistent behavior across byte-indexed and character-indexed text.

…ect too

Whether an overlong sequence is the character it spells, whether a lone leader
at the end of the subject sends the walk past the string buffer, and whether a
truncated leader in a class sends it past the pattern buffer are questions about
the bytes rather than about how the subject is indexed. Each is asked through a
UTF-8 subject only.

The engine reads a byte-indexed subject through a branch of its own:
`mrb_re_charlen()` and `mrb_re_decode_char()` take a flag for one and hand back
a byte at a time. So the walk that must stay inside the buffer at the end of
`"ab\xf0"` is a different walk there, and the decode that must not turn C0 BC
into `<` is a different decode. Ask each of them on that side as well, next to
the case it answers.
@takumin
takumin requested a review from matz as a code owner August 12, 2026 11:46
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: da3ebccb-0736-4150-a92f-a38905578cf1

📥 Commits

Reviewing files that changed from the base of the PR and between 19de6ff and a6da5b8.

📒 Files selected for processing (1)
  • mrbgems/mruby-regexp/test/regexp_utf8.rb

📝 Walkthrough

Walkthrough

The regexp UTF-8 test suite adds byte-indexed subject coverage for truncated, overlong, surrogate, and out-of-range sequences. The assertions verify boundary-safe matching and byte-wise scanning of invalid UTF-8.

Changes

UTF-8 regexp regression coverage

Layer / File(s) Summary
Boundary and invalid-sequence assertions
mrbgems/mruby-regexp/test/regexp_utf8.rb
Adds tests for truncated UTF-8 patterns and subjects. Adds tests confirming that invalid UTF-8 sequences do not match encoded characters and are scanned as individual bytes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • mruby/mruby#7068: Covers UTF-8 validation for truncated and invalid sequences on byte-indexed subjects.
  • mruby/mruby#7109: Changes shared UTF-8 boundary and validation behavior covered by these tests.
  • mruby/mruby#7110: Adds related malformed UTF-8 regression coverage in regexp_utf8.rb.

Suggested labels: mrbgems

Suggested reviewers: matz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding malformed UTF-8 sequence cases for byte-indexed subjects.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants