diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-19 02:37:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-05-19 02:37:38 +0000 |
commit | 780c056dadf26effeedaacf3e8a40576e0f91b77 (patch) | |
tree | 0d29f8513f148ff9e2aaddabb7869d519d40ff62 | |
parent | c2dc6960674c81fb4f0a8279f3470284bc0c740c (diff) |
re.c: match? should return nil if no match
* re.c (rb_reg_match_m_p): should return nil if no match, as the
document says. [Feature #8110]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55067 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | re.c | 6 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 6 |
3 files changed, 11 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Thu May 19 11:37:36 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * re.c (rb_reg_match_m_p): should return nil if no match, as the + document says. [Feature #8110] + Thu May 19 00:17:01 2016 NARUSE, Yui <naruse@ruby-lang.org> * re.c (reg_names_iter): specify capacify @@ -3230,7 +3230,7 @@ rb_reg_match_m_p(int argc, VALUE *argv, VALUE re) int tmpreg; rb_scan_args(argc, argv, "11", &str, &initpos); - if (NIL_P(str)) return Qnil; + if (NIL_P(str)) return Qfalse; str = SYMBOL_P(str) ? rb_sym2str(str) : rb_str_to_str(str); if (argc == 2) { pos = NUM2LONG(initpos); @@ -3238,14 +3238,14 @@ rb_reg_match_m_p(int argc, VALUE *argv, VALUE re) if (pos < 0) { pos += NUM2LONG(rb_str_length(str)); if (pos == 0) goto run; - if (pos < 0) return Qnil; + if (pos < 0) return Qfalse; } pos = rb_str_offset(str, pos); } run: if (pos >= RSTRING_LEN(str)) { - return Qnil; + return Qfalse; } reg = rb_reg_prepare_re0(re, str, err); tmpreg = reg != RREGEXP_PTR(re); diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 4d534114da..8f5c9ceaa2 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -528,13 +528,13 @@ class TestRegexp < Test::Unit::TestCase def test_match_p /backref/ =~ 'backref' - assert_nil(//.match?(nil)) + assert_equal(false, //.match?(nil)) assert_equal(true, /.../.match?(:abc)) assert_raise(TypeError) { /.../.match?(Object.new) } assert_equal(true, /../.match?('abc', 1)) assert_equal(true, /../.match?('abc', -2)) - assert_nil(/../.match?("abc", -4)) - assert_nil(/../.match?("abc", 4)) + assert_equal(false, /../.match?("abc", -4)) + assert_equal(false, /../.match?("abc", 4)) assert_equal(true, /../n.match?("\u3042" + '\x', 1)) assert_equal('backref', $&) end |