mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
re.c: fix name with NUL
* re.c (match_aref): should not ignore name after NUL byte. [ruby-dev:48275] [Bug #9902] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46344 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
161a0df797
commit
561fe11035
3 changed files with 24 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jun 4 21:23:52 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* re.c (match_aref): should not ignore name after NUL byte.
|
||||
[ruby-dev:48275] [Bug #9902]
|
||||
|
||||
Wed Jun 4 04:08:37 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* vm.c (core_hash_merge_kwd): should return the result hash, which
|
||||
|
|
10
re.c
10
re.c
|
@ -1796,17 +1796,13 @@ match_aref(int argc, VALUE *argv, VALUE match)
|
|||
|
||||
switch (TYPE(idx)) {
|
||||
case T_SYMBOL:
|
||||
p = rb_id2name(SYM2ID(idx));
|
||||
goto name_to_backref;
|
||||
break;
|
||||
idx = rb_sym2str(idx);
|
||||
/* fall through */
|
||||
case T_STRING:
|
||||
p = StringValuePtr(idx);
|
||||
|
||||
name_to_backref:
|
||||
num = name_to_backref_number(RMATCH_REGS(match),
|
||||
RMATCH(match)->regexp, p, p + strlen(p));
|
||||
RMATCH(match)->regexp, p, p + RSTRING_LEN(idx));
|
||||
return rb_reg_nth_match(num, match);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -142,6 +142,22 @@ class TestRegexp < Test::Unit::TestCase
|
|||
assert_equal("fbazo", s)
|
||||
end
|
||||
|
||||
def test_named_capture_with_nul
|
||||
bug9902 = '[ruby-dev:48275] [Bug #9902]'
|
||||
|
||||
m = /(?<a>.*)/.match("foo")
|
||||
assert_raise(IndexError, bug9902) {m["a\0foo"]}
|
||||
assert_raise(IndexError, bug9902) {m["a\0foo".to_sym]}
|
||||
|
||||
m = Regexp.new("(?<foo\0bar>.*)").match("xxx")
|
||||
assert_raise(IndexError, bug9902) {m["foo"]}
|
||||
assert_raise(IndexError, bug9902) {m["foo".to_sym]}
|
||||
assert_nothing_raised(IndexError, bug9902) {
|
||||
assert_equal("xxx", m["foo\0bar"], bug9902)
|
||||
assert_equal("xxx", m["foo\0bar".to_sym], bug9902)
|
||||
}
|
||||
end
|
||||
|
||||
def test_assign_named_capture
|
||||
assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
|
||||
assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))
|
||||
|
|
Loading…
Add table
Reference in a new issue