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