aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-19 02:37:38 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-19 02:37:38 +0000
commitdecc012cf07d4a55d2d01c2ad34e28c733bd32aa (patch)
tree0d29f8513f148ff9e2aaddabb7869d519d40ff62
parentacd962655f1d8c5376d7485104d3d54a3036e9d5 (diff)
downloadruby-decc012cf07d4a55d2d01c2ad34e28c733bd32aa.tar.gz
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--ChangeLog5
-rw-r--r--re.c6
-rw-r--r--test/ruby/test_regexp.rb6
3 files changed, 11 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index b6d390578f..cc2c6ae738 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/re.c b/re.c
index 36c12a6f6b..c83b3f5ba2 100644
--- a/re.c
+++ b/re.c
@@ -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