mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 99d8c4832a
: [Backport #18160]
Preserve the encoding of the argument in IndexError [Bug #18160] --- re.c | 20 ++++++++++---------- test/ruby/test_regexp.rb | 7 ++++++- 2 files changed, 16 insertions(+), 11 deletions(-)
This commit is contained in:
parent
d55426f800
commit
cd10572b05
3 changed files with 17 additions and 12 deletions
20
re.c
20
re.c
|
@ -1141,6 +1141,14 @@ match_size(VALUE match)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int name_to_backref_number(struct re_registers *, VALUE, const char*, const char*);
|
static int name_to_backref_number(struct re_registers *, VALUE, const char*, const char*);
|
||||||
|
NORETURN(static void name_to_backref_error(VALUE name));
|
||||||
|
|
||||||
|
static void
|
||||||
|
name_to_backref_error(VALUE name)
|
||||||
|
{
|
||||||
|
rb_raise(rb_eIndexError, "undefined group name reference: % "PRIsVALUE,
|
||||||
|
name);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
match_backref_number(VALUE match, VALUE backref)
|
match_backref_number(VALUE match, VALUE backref)
|
||||||
|
@ -1160,10 +1168,10 @@ match_backref_number(VALUE match, VALUE backref)
|
||||||
}
|
}
|
||||||
name = StringValueCStr(backref);
|
name = StringValueCStr(backref);
|
||||||
|
|
||||||
num = name_to_backref_number(regs, regexp, name, name + strlen(name));
|
num = name_to_backref_number(regs, regexp, name, name + RSTRING_LEN(backref));
|
||||||
|
|
||||||
if (num < 1) {
|
if (num < 1) {
|
||||||
rb_raise(rb_eIndexError, "undefined group name reference: %s", name);
|
name_to_backref_error(backref);
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
|
@ -1910,14 +1918,6 @@ name_to_backref_number(struct re_registers *regs, VALUE regexp, const char* name
|
||||||
(const unsigned char *)name, (const unsigned char *)name_end, regs);
|
(const unsigned char *)name, (const unsigned char *)name_end, regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
NORETURN(static void name_to_backref_error(VALUE name));
|
|
||||||
static void
|
|
||||||
name_to_backref_error(VALUE name)
|
|
||||||
{
|
|
||||||
rb_raise(rb_eIndexError, "undefined group name reference: % "PRIsVALUE,
|
|
||||||
name);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end) \
|
#define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end) \
|
||||||
(NIL_P(re) ? 0 : \
|
(NIL_P(re) ? 0 : \
|
||||||
!rb_enc_compatible(RREGEXP_SRC(re), (name)) ? 0 : \
|
!rb_enc_compatible(RREGEXP_SRC(re), (name)) ? 0 : \
|
||||||
|
|
|
@ -691,11 +691,16 @@ class TestRegexp < Test::Unit::TestCase
|
||||||
test = proc {|&blk| "abc".sub("a", ""); blk.call($~) }
|
test = proc {|&blk| "abc".sub("a", ""); blk.call($~) }
|
||||||
|
|
||||||
bug10877 = '[ruby-core:68209] [Bug #10877]'
|
bug10877 = '[ruby-core:68209] [Bug #10877]'
|
||||||
|
bug18160 = '[Bug #18160]'
|
||||||
test.call {|m| assert_raise_with_message(IndexError, /foo/, bug10877) {m["foo"]} }
|
test.call {|m| assert_raise_with_message(IndexError, /foo/, bug10877) {m["foo"]} }
|
||||||
key = "\u{3042}"
|
key = "\u{3042}"
|
||||||
[Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
|
[Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
|
||||||
idx = key.encode(enc)
|
idx = key.encode(enc)
|
||||||
test.call {|m| assert_raise_with_message(IndexError, /#{idx}/, bug10877) {m[idx]} }
|
pat = /#{idx}/
|
||||||
|
test.call {|m| assert_raise_with_message(IndexError, pat, bug10877) {m[idx]} }
|
||||||
|
test.call {|m| assert_raise_with_message(IndexError, pat, bug18160) {m.offset(idx)} }
|
||||||
|
test.call {|m| assert_raise_with_message(IndexError, pat, bug18160) {m.begin(idx)} }
|
||||||
|
test.call {|m| assert_raise_with_message(IndexError, pat, bug18160) {m.end(idx)} }
|
||||||
end
|
end
|
||||||
test.call {|m| assert_equal(/a/, m.regexp) }
|
test.call {|m| assert_equal(/a/, m.regexp) }
|
||||||
test.call {|m| assert_equal("abc", m.string) }
|
test.call {|m| assert_equal("abc", m.string) }
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||||
#define RUBY_VERSION_TEENY 5
|
#define RUBY_VERSION_TEENY 5
|
||||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||||
#define RUBY_PATCHLEVEL 197
|
#define RUBY_PATCHLEVEL 198
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2021
|
#define RUBY_RELEASE_YEAR 2021
|
||||||
#define RUBY_RELEASE_MONTH 11
|
#define RUBY_RELEASE_MONTH 11
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue