Project

General

Profile

Bug #7092

StringScanner start-of-line matches false positives, while lookbehind for a newline gives false negatives

Added by jayferd (Jay Adkisson) almost 5 years ago. Updated about 4 years ago.

Status:
Rejected
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
Backport:
[ruby-core:47759]

Description

To reproduce:

>> require 'strscan'
>> ss = StringScanner.new("ab")
>> ss.scan(/./)
=> "a"
>> ss.scan(/^./) # expecting nil, since the head is in the middle of a line
=> "b"

As a workaround-that-didn't-work, I also tried looking behind for a newline, which seems never to match, even with the m flag.

>> ss = StringScanner.new("a\nb")
>> ss.scan(/../m)
=> "a\n"
>> ss.scan(/(?<=\n)./m) # expecting "b", since the previous char is a newline
=> nil

History

#1 [ruby-core:48143] Updated by jayferd (Jay Adkisson) almost 5 years ago

Bump. Can someone confirm whether or not this is expected behavior?

#2 [ruby-core:48756] Updated by jayferd (Jay Adkisson) almost 5 years ago

I've now reproduced this in 2.0.0-preview1. Is anyone out there...?

#3 [ruby-core:48758] Updated by mame (Yusuke Endoh) almost 5 years ago

  • Status changed from Open to Feedback
  • Assignee set to mame (Yusuke Endoh)
  • Target version set to 2.0.0

Sorry for late reply.

Honestly, it is difficult to say whether it is intended or a bug because there is no strscan maintainer.
But since 1.8, StringScanner#scan has behaved so. I guess there is some existing programs that depends on the behavior.

Therefore, I'd like not to change the behavior unless there is no special reason.
Do you have any special reason? Or do you just want to confirm?

--
Yusuke Endoh mame@tsg.ne.jp

#4 [ruby-core:48759] Updated by mame (Yusuke Endoh) almost 5 years ago

FYI: You may want to use StringScanner#beginning_of_line?.

--
Yusuke Endoh mame@tsg.ne.jp

#5 [ruby-core:48761] Updated by nobu (Nobuyoshi Nakada) almost 5 years ago

I guess it would be intentional.
'' and '\A' are `beginning of the target' (and beginning of a line for ) anchors, so seems reasonable that it matches the beginning of the part to be matched.

#6 [ruby-core:52038] Updated by mame (Yusuke Endoh) over 4 years ago

  • Priority changed from Normal to 3
  • Target version changed from 2.0.0 to next minor

#7 [ruby-core:55215] Updated by mame (Yusuke Endoh) about 4 years ago

  • Status changed from Feedback to Rejected

I'm marking this ticket as closed due to no feedback.

--
Yusuke Endoh mame@tsg.ne.jp

Also available in: Atom PDF