Backport #8001
closed2.0 Regexp \Z matches where it shouldn't
Description
=begin
for ruby in ~/.rbenv/versions/{1.9.3-p327,2.0.0-p0}/bin/ruby
do
"$ruby" -v
"$ruby" -e 'p /x.*?\Z$/ =~ "x\ny"'
done
:In Ruby 1.9: (({nil}))
:In Ruby 2.0: (({0}))
If you remove the "y" from the string, or add more, then they do the same thing.
The temporary solution I'm using to get around this is to replace (({\Z}))
with (({\n\z}))
=end
Updated by josh.cheek (Josh Cheek) almost 12 years ago
Pasted version from 1.9, here is my actual output with both versions:
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
nil
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
0
Updated by josh.cheek (Josh Cheek) almost 12 years ago
Also realized the regex here ends with \Z$, but can be shown with just \Z.
Here is an updated example:
versions¶
$ for n in 1.9 2; do ruby$n -v; done
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
This one made me think that maybe the /m flag is set¶
$ for n in 1.9 2; do ruby$n -e 'p "x\ny"[/\A.*\Z/]'; done
nil
"x"
But it's not:¶
$ for n in 1.9 2; do ruby$n -e 'p "x\ny"[/\A.*\Z/m]'; done
"x\ny"
"x\ny"
$ for n in 1.9 2; do ruby$n -e 'p "x\ny"[/x.*y/]'; done
nil
nil
And the behaviour can be shown to exist even with the /m flag on¶
$ for n in 1.9 2; do ruby$n -e 'p "x\ny"[/.*?\Z/m]'; done
"x\ny"
"x"
Updated by nobu (Nobuyoshi Nakada) almost 12 years ago
- Description updated (diff)
Updated by naruse (Yui NARUSE) over 11 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r39718.
Josh, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Status changed from Closed to Assigned
- Assignee set to nagachika (Tomoyuki Chikanaga)
Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago
- Status changed from Assigned to Closed
This issue was solved with changeset r40088.
Josh, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 39718: [Backport #8001] [Backport #8023]
* Merge Onigmo d4bad41e16e3eccd97ccce6f1f96712e557c4518.
fix lookbehind assertion fails with /m mode enabled. [Bug #8023]
fix \Z matches where it shouldn't. [Bug #8001]