Project

General

Profile

Actions

Backport #8001

closed

2.0 Regexp \Z matches where it shouldn't

Added by josh.cheek (Josh Cheek) about 11 years ago. Updated almost 11 years ago.


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) about 11 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) about 11 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) about 11 years ago

  • Description updated (diff)
Actions #4

Updated by naruse (Yui NARUSE) about 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.


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

Updated by nagachika (Tomoyuki Chikanaga) about 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)
Actions #6

Updated by nagachika (Tomoyuki Chikanaga) almost 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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0