Forum: Ruby-core [ruby-trunk - Bug #8023][Open] Lookbehind assertion fails with /m mode enabled

Posted by pietzcker (Tim Pietzcker) (Guest)
on 2013-03-05 22:39
(Received via mailing list)
Issue #8023 has been reported by pietzcker (Tim Pietzcker).

----------------------------------------
Bug #8023: Lookbehind assertion fails with /m mode enabled
https://bugs.ruby-lang.org/issues/8023

Author: pietzcker (Tim Pietzcker)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24) [x64-mingw32]


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
Posted by pietzcker (Tim Pietzcker) (Guest)
on 2013-03-05 22:42
(Received via mailing list)
Issue #8023 has been updated by pietzcker (Tim Pietzcker).


Tested on Ruby 2.0.0 and 1.9.3p392
----------------------------------------
Bug #8023: Lookbehind assertion fails with /m mode enabled
https://bugs.ruby-lang.org/issues/8023#change-37316

Author: pietzcker (Tim Pietzcker)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24) [x64-mingw32]


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
Posted by pietzcker (Tim Pietzcker) (Guest)
on 2013-03-05 22:58
(Received via mailing list)
Issue #8023 has been updated by pietzcker (Tim Pietzcker).


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
----------------------------------------
Bug #8023: Lookbehind assertion fails with /m mode enabled
https://bugs.ruby-lang.org/issues/8023#change-37317

Author: pietzcker (Tim Pietzcker)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24) [x64-mingw32]


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
Posted by pietzcker (Tim Pietzcker) (Guest)
on 2013-03-06 07:54
(Received via mailing list)
Issue #8023 has been updated by pietzcker (Tim Pietzcker).


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
----------------------------------------
Bug #8023: Lookbehind assertion fails with /m mode enabled
https://bugs.ruby-lang.org/issues/8023#change-37324

Author: pietzcker (Tim Pietzcker)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24) [x64-mingw32]


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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.