Regexp#[] ignores after NUL byte in named capture index

Issue #9902 has been updated by Usaku NAKAMURA.

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

backported into ruby_2_0_0 at r47334.


Bug #9902: Regexp#[] ignores after NUL byte in named capture index

  • Author: Nobuyoshi N.
  • Status: Closed
  • Priority: Normal
  • Assignee:
  • Category:
  • Target version:
  • ruby -v: r46343
  • Backport: 2.0.0: DONE, 2.1: DONE

Regexp#[]に"\0"を含む文字列やシンボルを指定したとき、それ以降が無視されます。

$ ruby -w -e 'p(/(?<a>.*)/.match("foo")["a\0foo"])'
"foo"

$ ruby -w -e 'p Regexp.new("(?<foo\0bar>.*?)").match("xxx")["foo\0bar"]'
-e:1:in `[]': undefined group name reference: foo (IndexError)
  from -e:1:in `<main>'