186ebd63da (master): [ruby/strscan] Reset the number of registers after string pattern

0 views
Skip to first unread message

Sutou Kouhei

unread,
12:58 AM (17 hours ago) 12:58 AM
to ruby...@g.ruby-lang.org
Sutou Kouhei 2026-10-06 04:57:56 +0000 (Tue, 06 Oct 2026)

New Revision: 186ebd63da

https://github.com/ruby/ruby/commit/186ebd63da

Log:
[ruby/strscan] Reset the number of registers after string pattern
match
(https://github.com/ruby/strscan/pull/221)

`set_registers()` used `onig_region_set()` that doesn't change
`num_regs` when the region is already allocated. So `StringScanner#size`
and `#captures` after a string pattern match reported the number of
registers of the previous `Regexp` match:

```ruby
s = StringScanner.new("abc")
s.scan(/(a)(b)/)
s.scan("c")
s.size # => 3 (should be 1)
s.captures # => [nil, nil] (should be [])
```

Use `onig_region_resize()` like `adjust_registers_to_matched()` does.
This is consistent with the JRuby and TruffleRuby implementations.

https://github.com/ruby/strscan/commit/f829eade26

Co-authored-by: Claude Opus 5.5 <nor...@anthropic.com>

Modified files:
ext/strscan/strscan.c
test/strscan/test_stringscanner.rb
Reply all
Reply to author
Forward
0 new messages