Bug #9902

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

Added by Nobuyoshi Nakada 12 months ago. Updated 9 months ago.

[ruby-dev:48275]
Status:Closed
Priority:Normal
Assignee:-
ruby -v:r46343 Backport:2.0.0: DONE, 2.1: DONE

Description

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>'

Associated revisions

Revision 46344
Added by Nobuyoshi Nakada 12 months ago

re.c: fix name with NUL

  • re.c (match_aref): should not ignore name after NUL byte. [Bug #9902]

Revision 46344
Added by Nobuyoshi Nakada 12 months ago

re.c: fix name with NUL

  • re.c (match_aref): should not ignore name after NUL byte. [Bug #9902]

Revision 46869
Added by Tomoyuki Chikanaga 10 months ago

merge revision(s) r46344: [Backport #9902]

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

Revision 47334
Added by Usaku NAKAMURA 9 months ago

merge revision(s) 46344: [Backport #9902]

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

History

#1 Updated by Nobuyoshi Nakada 12 months ago

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

Applied in changeset r46344.


re.c: fix name with NUL

  • re.c (match_aref): should not ignore name after NUL byte. [Bug #9902]

#2 Updated by Nobuyoshi Nakada 12 months ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

#3 Updated by Tomoyuki Chikanaga 11 months ago

rb_sym2str() doesn't exist in 2.1. Can I use rb_sym_to_s() instead?

#4 Updated by Nobuyoshi Nakada 11 months ago

Yes, or rb_id2str(SYM2ID(idx)).

#5 Updated by Tomoyuki Chikanaga 10 months ago

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

backported into ruby_2_1 branch at r46869.

#6 Updated by Usaku NAKAMURA 9 months ago

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

Also available in: Atom PDF