Backport #8023

Lookbehind assertion fails with /m mode enabled

Added by Tim Pietzcker about 2 years ago. Updated about 2 years ago.

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

Description

Lookbehind assertions fail if they are longer than one character, and if dotall mode is set.

irb(main):001:0> "foo" =~ /(?<=f)./m
=> 1
irb(main):002:0> "foo" =~ /(?<=fo).
/m
=> nil

The latter should have matched the "o". This only seems to happen with dotall mode turned on (dot matches newline); without it, everything is OK:

irb(main):003:0> "foo" =~ /(?<=f)./
=> 1
irb(main):004:0> "foo" =~ /(?<=fo).
/
=> 2


Related issues

Related to Backport193 - Backport #8076: Lookbehind assertion fails with /m mode enabled Closed 03/06/2013

Associated revisions

Revision 39718
Added by Yui NARUSE about 2 years ago

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

Revision 40088
Added by Tomoyuki Chikanaga about 2 years 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 Tim Pietzcker about 2 years ago

Tested on Ruby 2.0.0 and 1.9.3p392

#2 Updated by Tim Pietzcker about 2 years ago

Some more observations:

Adding an end-of-line anchor doesn't change anything:

irb(main):016:0> "foo" =~ /(?<=fo).*$/m
=> nil

But together with a lazy quantifier, it "works":

irb(main):017:0> "foo" =~ /(?<=fo).*?$/m
=> 2

#3 Updated by Tim Pietzcker about 2 years ago

More observations:

.+ works as does its equivalent {1,}, but only in Ruby 1.9 (it seems that that's the only behavioral difference between the two in this scenario):

pry(main)> "foo" =~ /(?<=fo).+/m
=> 2
pry(main)> "foo" =~ /(?<=fo).{1,}/m
=> 2

In Ruby 2.0:

irb(main):018:0> "foo" =~ /(?<=fo).+/m
=> nil
irb(main):019:0> "foo" =~ /(?<=fo).{1,}/m
=> nil

.{0,} is busted (in both 1.9 and 2.0):

pry(main)> "foo" =~ /(?<=fo).{0,}/m
=> nil

But {n,m} works in both:

pry(main)> "foo" =~ /(?<=fo).{0,1}/m
=> 2
pry(main)> "foo" =~ /(?<=fo).{0,2}/m
=> 2
pry(main)> "foo" =~ /(?<=fo).{0,9999}/m
=> 2
pry(main)> "foo" =~ /(?<=fo).{1,999}/m
=> 2

#4 Updated by Yui NARUSE about 2 years ago

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

This issue was solved with changeset r39718.
Tim, 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 Yui NARUSE about 2 years 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 2 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40088.
Tim, 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