develooper Front page | perl.perl5.porters | Postings from March 2014

Re: [perl #121484] /m causing false negative

Thread Previous | Thread Next
From:
Aaron Crane
Date:
March 21, 2014 14:33
Subject:
Re: [perl #121484] /m causing false negative
Message ID:
CACmk_ttKxo+SWBq6_MYM6v2ZtPkFtdJBe43R_Cz1B4SHUB4Uqw@mail.gmail.com
Zefram <perlbug-followup@perl.org> wrote:
> $ perl5.19.10 -lwe 'print "wibble" =~ /\Awibble\z/m ? "yes" : "no"'
> no
> $ perl5.19.9 -lwe 'print "wibble" =~ /\Awibble\z/m ? "yes" : "no"'
> yes

This bisects to the following commit:

commit d0d4464849e2b30aee89c175ccb5465795de10ce
Author: David Mitchell <davem@iabyn.com>
Date:   Tue Mar 18 20:15:27 2014 +0000

    re_intuit_start(): reduce scope of /^...$/m test

    Intuit has a quick reject test for a fixed pattern that is anchored at
    both ends. For example, with the pattern /^abcd$/, only the exact strings
    "abcd" or "abcd\n" will match; anything else, and the match immediately
    fails.

    A fix for [perl #115242] correctly made intuit skip the test in the
    presence of //m, since in this case the $ doesn't necessarily correspond
    to the end of the string.

    However, the fix was too wide in scope; it caused //m patterns to skip
    searching for a known string anchored just at the start, as well as one
    anchored at both ends.

    With this commit, the following code now runs in a few milliseconds rather
    than a few seconds on my machine:

        $s = "abcdefg" x 1_000_000;
        $s =~ /(?-m:^)abcX?fg/m for 1..100;

AFAICT from a fairly cursory look, re_intuit_start() seems to be
failing to account for the "\n" at the end of the fixed check
substring.

This is Zefram's test case expressed in the language of t/re/re_tests:

diff --git i/t/re/re_tests w/t/re/re_tests
index 7ab7dc3..294032f 100644
--- i/t/re/re_tests
+++ w/t/re/re_tests
@@ -1884,5 +1884,21 @@ A+(*PRUNE)BC(?{})        AAABC   y       $&      AAABC
 [bcd].{2,3}aaaa        XbXaaaaa        y       -       -
 [bcd].{2,3}aaaa        Xb\x{100}aaaaa  y       -       -

+# RT #121484 - /m causing false negative
+'\Awibble\z'm  wibble  y       $&      wibble
+'\A.ibble\z'm  wibble  y       $&      wibble
+'\Aw.bble\z'm  wibble  y       $&      wibble
+'\Awi.ble\z'm  wibble  y       $&      wibble
+'\Awib.le\z'm  wibble  y       $&      wibble
+'\Awibb.e\z'm  wibble  y       $&      wibble
+'\Awibbl.\z'm  wibble  y       $&      wibble
+'\Awibble$'m   wibble  y       $&      wibble
+'\A.ibble$'m   wibble  y       $&      wibble
+'\Aw.bble$'m   wibble  y       $&      wibble
+'\Awi.ble$'m   wibble  y       $&      wibble
+'\Awib.le$'m   wibble  y       $&      wibble
+'\Awibb.e$'m   wibble  y       $&      wibble
+'\Awibbl.$'m   wibble  y       $&      wibble
+
 # Keep these lines at the end of the file
 # vim: softtabstop=0 noexpandtab

-- 
Aaron Crane ** http://aaroncrane.co.uk/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About