mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 21:44:30 +02:00
re.c: consider name encoding
* re.c (match_aref, rb_reg_regsub): consider encoding of captured names, encoding-incompatible should not match. [ruby-dev:48278] [Bug #9903] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ea0e8e61c0
commit
5861d4f18b
3 changed files with 22 additions and 6 deletions
|
@ -158,6 +158,15 @@ class TestRegexp < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_named_capture_nonascii
|
||||
bug9903 = '[ruby-dev:48278] [Bug #9903]'
|
||||
|
||||
key = "\xb1\xb2".force_encoding(Encoding::EUC_JP)
|
||||
m = /(?<#{key}>.*)/.match("xxx")
|
||||
assert_equal("xxx", m[key])
|
||||
assert_raise(IndexError, bug9903) {m[key.dup.force_encoding(Encoding::Shift_JIS)]}
|
||||
end
|
||||
|
||||
def test_assign_named_capture
|
||||
assert_equal("a", eval('/(?<foo>.)/ =~ "a"; foo'))
|
||||
assert_equal("a", eval('foo = 1; /(?<foo>.)/ =~ "a"; foo'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue