From 2800e6a0a49d68ace9315fbff4fb444d12d11dec Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 12 Dec 2016 02:38:53 +0000 Subject: [PATCH] re.c: char boundary * re.c (rb_reg_match_m_p): consider char boundary. rb_str_subpos does not adjust to the boundary if len == 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57051 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- re.c | 4 ++-- test/ruby/test_regexp.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/re.c b/re.c index 2d786f5cef..95ba903480 100644 --- a/re.c +++ b/re.c @@ -3243,8 +3243,8 @@ rb_reg_match_m_p(int argc, VALUE *argv, VALUE re) if (pos < 0) return Qfalse; } if (pos > 0) { - long len = 0; - char *beg = rb_str_subpos(str, pos, &len); + long len = 1; + const char *beg = rb_str_subpos(str, pos, &len); if (!beg) return Qfalse; pos = beg - RSTRING_PTR(str); } diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index c93ed968d1..7eac2debbd 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -543,7 +543,8 @@ class TestRegexp < Test::Unit::TestCase assert_equal(true, /../.match?('abc', -2)) assert_equal(false, /../.match?("abc", -4)) assert_equal(false, /../.match?("abc", 4)) - assert_equal(true, /../n.match?("\u3042" + '\x', 1)) + assert_equal(true, /../.match?("\u3042xx", 1)) + assert_equal(false, /../.match?("\u3042x", 1)) assert_equal(true, /\z/.match?("")) assert_equal(true, /\z/.match?("abc")) assert_equal(true, /R.../.match?("Ruby"))