re.c: RMatch::regexp can be nil
* re.c (match_aref): RMatch::regexp is Qnil after matching by a string since r45451. [ruby-core:68209] [Bug #10877] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
516e463aaf
commit
2d12151a68
@ -1,3 +1,8 @@
|
|||||||
|
Sat Feb 21 19:51:49 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* re.c (match_aref): RMatch::regexp is Qnil after matching by a
|
||||||
|
string since r45451. [ruby-core:68209] [Bug #10877]
|
||||||
|
|
||||||
Sat Feb 21 16:18:42 2015 Stefan Schuler <mail@stefanschuessler.de>
|
Sat Feb 21 16:18:42 2015 Stefan Schuler <mail@stefanschuessler.de>
|
||||||
|
|
||||||
* compar.c (Init_Comparable): [DOC] Replace camelcase variable name.
|
* compar.c (Init_Comparable): [DOC] Replace camelcase variable name.
|
||||||
|
5
re.c
5
re.c
@ -1787,7 +1787,7 @@ name_to_backref_error(VALUE name)
|
|||||||
static VALUE
|
static VALUE
|
||||||
match_aref(int argc, VALUE *argv, VALUE match)
|
match_aref(int argc, VALUE *argv, VALUE match)
|
||||||
{
|
{
|
||||||
VALUE idx, rest;
|
VALUE idx, rest, re;
|
||||||
|
|
||||||
match_check(match);
|
match_check(match);
|
||||||
rb_scan_args(argc, argv, "11", &idx, &rest);
|
rb_scan_args(argc, argv, "11", &idx, &rest);
|
||||||
@ -1808,7 +1808,8 @@ match_aref(int argc, VALUE *argv, VALUE match)
|
|||||||
/* fall through */
|
/* fall through */
|
||||||
case T_STRING:
|
case T_STRING:
|
||||||
p = StringValuePtr(idx);
|
p = StringValuePtr(idx);
|
||||||
if (!rb_enc_compatible(RREGEXP(RMATCH(match)->regexp)->src, idx) ||
|
re = RMATCH(match)->regexp;
|
||||||
|
if (NIL_P(re) || !rb_enc_compatible(RREGEXP(re)->src, idx) ||
|
||||||
(num = name_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp,
|
(num = name_to_backref_number(RMATCH_REGS(match), RMATCH(match)->regexp,
|
||||||
p, p + RSTRING_LEN(idx))) < 1) {
|
p, p + RSTRING_LEN(idx))) < 1) {
|
||||||
name_to_backref_error(idx);
|
name_to_backref_error(idx);
|
||||||
|
@ -545,6 +545,19 @@ class TestRegexp < Test::Unit::TestCase
|
|||||||
assert_equal("foo", $&)
|
assert_equal("foo", $&)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_match_without_regexp
|
||||||
|
bug10877 = '[ruby-core:68209] [Bug #10877]'
|
||||||
|
"abc".sub("a", "")
|
||||||
|
assert_raise_with_message(IndexError, /foo/, bug10877) {$~["foo"]}
|
||||||
|
key = "\u{3042}"
|
||||||
|
[Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
|
||||||
|
idx = key.encode(enc)
|
||||||
|
EnvUtil.with_default_external(enc) do
|
||||||
|
assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_last_match
|
def test_last_match
|
||||||
/(...)(...)(...)(...)?/.match("foobarbaz")
|
/(...)(...)(...)(...)?/.match("foobarbaz")
|
||||||
assert_equal("foobarbaz", Regexp.last_match(0))
|
assert_equal("foobarbaz", Regexp.last_match(0))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user