Issue #11825 has been updated by Usaku NAKAMURA.

Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED

ruby_2_1 r53920 merged revision(s) 53167.

----------------------------------------
Bug #11825: MatchData#names returns ASCII-8BIT
https://bugs.ruby-lang.org/issues/11825#change-57125

* Author: Toru Iwase
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]
* Backport: 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED
----------------------------------------
`MatchData#names` returns ASCII-8BIT.
But `MatchData#[]` doesn't accept ASCII-8BIT name if name has non-ASCII chars.

`MatchData#names` should return same encoding of regexp. (UTF-8 by default)

~~~
$ irb
ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]
irb(main):001:0> m = /(?<宝石>ルビー)/.match('ルビー')
=> #<MatchData "ルビー" 宝石:"ルビー">
irb(main):002:0> m.names
=> ["\xE5\xAE\x9D\xE7\x9F\xB3"]
irb(main):003:0> m[m.names[0]]
IndexError: undefined group name reference: "\xE5\xAE\x9D\xE7\x9F\xB3"
        from (irb):3:in `[]'
        from (irb):3
        from /usr/local/anyenv/envs/rbenv/versions/2.3.0-preview2/bin/irb:11:in `<main>'
irb(main):004:0> m['宝石']
=> "ルビー"
irb(main):005:0> m.names[0].encoding
=> #<Encoding:ASCII-8BIT>
irb(main):006:0> m = /(?<gem>ルビー)/.match('ルビー')
=> #<MatchData "ルビー" gem:"ルビー">
irb(main):007:0> m.names
=> ["gem"]
irb(main):008:0> m.names[0].encoding
=> #<Encoding:ASCII-8BIT>
irb(main):009:0> m[m.names[0]]
=> "ルビー"
~~~




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>