diff options
author | Sutou Kouhei <[email protected]> | 2025-04-29 07:17:47 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2025-05-02 09:52:38 +0900 |
commit | af6d6b64eafc8f9353804cd8c8192a2afed0d6e5 () | |
tree | 8521cc6894b73a1734f279b1d5d4459a7e205930 | |
parent | a1e627b7e3a081a9ab52b04ef4a8e4930caa0cf2 (diff) |
[ruby/strscan] named_captures: fix incompatibility with
MatchData#named_captures (https://.com/ruby/strscan/pull/146) Fix https://.com/ruby/strscan/pull/145 `MatchData#named_captures` use the last matched value for each name. Reported by Linus Sellberg. Thanks!!! https://.com/ruby/strscan/commit/a6086ea322
-rw-r--r-- | ext/strscan/strscan.c | 5 | ||||
-rw-r--r-- | test/strscan/test_stringscanner.rb | 6 |
2 files changed, 10 insertions, 1 deletions
@@ -2211,7 +2211,10 @@ named_captures_iter(const OnigUChar *name, VALUE value = RUBY_Qnil; int i; for (i = 0; i < back_num; i++) { - value = strscan_aref(data->self, INT2NUM(back_refs[i])); } rb_hash_aset(data->captures, key, value); return 0; @@ -967,6 +967,12 @@ module StringScannerTests assert_equal({}, scan.named_captures) end def test_scan_integer s = create_string_scanner('abc') assert_equal(3, s.match?(/(?<a>abc)/)) # set named_captures |