Skip to content

Commit bdb5ef9

Browse files
committed
merge revision(s) r46344: [Backport ruby#9902]
* re.c (match_aref): should not ignore name after NUL byte. [ruby-dev:48275] [Bug ruby#9902] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent c7391a0 commit bdb5ef9

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Sat Jul 19 01:44:34 2014 Nobuyoshi Nakada <[email protected]>
2+
3+
* re.c (match_aref): should not ignore name after NUL byte.
4+
[ruby-dev:48275] [Bug #9902]
5+
16
Sun Jul 13 23:28:41 2014 SHIBATA Hiroshi <[email protected]>
27

38
* test/test_timeout.rb (test_timeout): inverted test condition.

re.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,17 +1754,13 @@ match_aref(int argc, VALUE *argv, VALUE match)
17541754

17551755
switch (TYPE(idx)) {
17561756
case T_SYMBOL:
1757-
p = rb_id2name(SYM2ID(idx));
1758-
goto name_to_backref;
1759-
break;
1757+
idx = rb_id2str(SYM2ID(idx));
1758+
/* fall through */
17601759
case T_STRING:
17611760
p = StringValuePtr(idx);
1762-
1763-
name_to_backref:
17641761
num = name_to_backref_number(RMATCH_REGS(match),
1765-
RMATCH(match)->regexp, p, p + strlen(p));
1762+
RMATCH(match)->regexp, p, p + RSTRING_LEN(idx));
17661763
return rb_reg_nth_match(num, match);
1767-
break;
17681764

17691765
default:
17701766
break;

test/ruby/test_regexp.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ def test_named_capture
142142
assert_equal("fbazo", s)
143143
end
144144

145+
def test_named_capture_with_nul
146+
bug9902 = '[ruby-dev:48275] [Bug #9902]'
147+
148+
m = /(?<a>.*)/.match("foo")
149+
assert_raise(IndexError, bug9902) {m["a\0foo"]}
150+
assert_raise(IndexError, bug9902) {m["a\0foo".to_sym]}
151+
152+
m = Regexp.new("(?<foo\0bar>.*)").match("xxx")
153+
assert_raise(IndexError, bug9902) {m["foo"]}
154+
assert_raise(IndexError, bug9902) {m["foo".to_sym]}
155+
assert_nothing_raised(IndexError, bug9902) {
156+
assert_equal("xxx", m["foo\0bar"], bug9902)
157+
assert_equal("xxx", m["foo\0bar".to_sym], bug9902)
158+
}
159+
end
160+
145161
def test_assign_named_capture
146162
assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
147163
assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.2"
2-
#define RUBY_RELEASE_DATE "2014-07-13"
3-
#define RUBY_PATCHLEVEL 175
2+
#define RUBY_RELEASE_DATE "2014-07-19"
3+
#define RUBY_PATCHLEVEL 176
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 7
7-
#define RUBY_RELEASE_DAY 13
7+
#define RUBY_RELEASE_DAY 19
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)