Project

General

Profile

Actions

Backport #8023

closed

Lookbehind assertion fails with /m mode enabled

Added by pietzcker (Tim Pietzcker) over 11 years ago. Updated over 11 years ago.


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 1 (0 open1 closed)

Related to Backport193 - Backport #8076: Lookbehind assertion fails with /m mode enabledClosedusa (Usaku NAKAMURA)03/06/2013Actions

Updated by pietzcker (Tim Pietzcker) over 11 years ago

Tested on Ruby 2.0.0 and 1.9.3p392

Updated by pietzcker (Tim Pietzcker) over 11 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) over 11 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

Actions #4

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.
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]
Actions #5

Updated by naruse (Yui NARUSE) 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)
Actions #6

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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0