Backport #8001

2.0 Regexp \Z matches where it shouldn't

Added by Josh Cheek about 1 year ago. Updated about 1 year ago.

[ruby-core:53101]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

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

Associated revisions

Revision 40088
Added by Tomoyuki Chikanaga about 1 year ago

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]

History

#1 Updated by Josh Cheek about 1 year ago

Pasted version from 1.9, here is my actual output with both versions:

ruby 1.9.3p327 (2012-11-10 revision 37606) [x8664-darwin12.2.0]
nil
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86
64-darwin12.2.0]
0

#2 Updated by Josh Cheek about 1 year 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) [x8664-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"

#3 Updated by Nobuyoshi Nakada about 1 year ago

  • Description updated (diff)

#4 Updated by Yui NARUSE about 1 year 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.


  • Merge Onigmo d4bad41e16e3eccd97ccce6f1f96712e557c4518. fix lookbehind assertion fails with /m mode enabled. [Bug #8023] fix \Z matches where it shouldn't. [Bug #8001]

#5 Updated by Tomoyuki Chikanaga about 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Status changed from Closed to Assigned
  • Assignee set to Tomoyuki Chikanaga

#6 Updated by Tomoyuki Chikanaga about 1 year 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]

Also available in: Atom PDF