Project

General

Profile

Actions

Bug #11825

closed

MatchData#names returns ASCII-8BIT

Added by Tietew (Toru Iwase) over 8 years ago. Updated about 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]
[ruby-core:72185]

Description

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]]
=> "ルビー"
Actions #1

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Status changed from Open to Closed

Applied in changeset r53167.


re.c: names encoding

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Description updated (diff)
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED

Updated by usa (Usaku NAKAMURA) about 8 years ago

  • 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.

Actions #4

Updated by nagachika (Tomoyuki Chikanaga) about 8 years ago

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

Backported into ruby_2_2 branch at r54036.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0