Forum: Ruby-dev [Closed] Regexp#[] ignores after NUL byte in named capture index

F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2014-06-04 14:24
(Received via mailing list)
Issue #9902 has been updated by Nobuyoshi Nakada.

Status changed from Open to Closed
% Done changed from 0 to 100

Applied in changeset r46344.

----------
re.c: fix name with NUL

* re.c (match_aref): should not ignore name after NUL byte.
  [ruby-dev:48275] [Bug #9902]

----------------------------------------
Bug #9902: Regexp#[] ignores after NUL byte in named capture index
https://bugs.ruby-lang.org/issues/9902#change-47036

* Author: Nobuyoshi Nakada
* Status: Closed
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: r46343
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
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>'
~~~
This topic is locked and can not be replied to.