Skip to content

Commit

Permalink
[ruby/strscan] Sync missed commit
Browse files Browse the repository at this point in the history
Syncs commit ruby/strscan@76b377a.
  • Loading branch information
peterzhu2118 committed Jul 27, 2023
1 parent ccca097 commit e27eab2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/strscan/strscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,9 @@ strscan_named_captures(VALUE self)
named_captures_data data;
data.self = self;
data.captures = rb_hash_new();
onig_foreach_name(RREGEXP_PTR(p->regex), named_captures_iter, &data);
if (!RB_NIL_P(p->regex)) {
onig_foreach_name(RREGEXP_PTR(p->regex), named_captures_iter, &data);
}

return data.captures;
}
Expand Down
1 change: 1 addition & 0 deletions test/strscan/test_stringscanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ def test_scan_aref_repeatedly
def test_named_captures
omit("not implemented on TruffleRuby") if ["truffleruby"].include?(RUBY_ENGINE)
scan = StringScanner.new("foobarbaz")
assert_equal({}, scan.named_captures)
assert_equal(9, scan.match?(/(?<f>foo)(?<r>bar)(?<z>baz)/))
assert_equal({"f" => "foo", "r" => "bar", "z" => "baz"}, scan.named_captures)
end
Expand Down

0 comments on commit e27eab2

Please sign in to comment.