Backport #8023
closedLookbehind assertion fails with /m mode enabled
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
Updated by pietzcker (Tim Pietzcker) almost 12 years ago
Tested on Ruby 2.0.0 and 1.9.3p392
Updated by pietzcker (Tim Pietzcker) almost 12 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
Updated by pietzcker (Tim Pietzcker) almost 12 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
Updated by naruse (Yui NARUSE) almost 12 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.
Updated by naruse (Yui NARUSE) almost 12 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.
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]