www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9211] New: regex lookahead, (?=(\d\d\d)+\b) failed

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211

           Summary: regex lookahead, (?=(\d\d\d)+\b) failed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: p.summerland gmail.com


--- Comment #0 from Peter Summerland <p.summerland gmail.com> 2012-12-26
14:13:35 PST ---
The following failed for more than six digits:

auto rx_bf_ddd = regex( r"(?<=\d)(?=(\d\d\d)+\b)", "g");
writefln( "rx_bf_ddd:  %s ", replace(digits, rx_bf_ddd, ",") );

Using (\d{3}) i/o (\d\d\d) worked.

DMD64 D Compiler v2.060

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 26 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com


--- Comment #1 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-12-27
08:15:19 PST ---
Now that was neasty.
The bug lurked in a branch-test code of *-repetition. It was too optimistic
optimization and it was curbed down back then. Looks like one case slipped
through.

The reduced test case doesn't require lookahead at all: 

version A1 prints [["123", "12", "3"]] (!!)
version A2 prints [["1234", "3", "4"]]

The bug is triggered in a specific scenarios but is quite deadly.

import std.regex, std.stdio;

int main(string[] args)
{
    version(A1)
    {
      auto rx_1 =  regex(r"^(\w)*(\d)");
      auto m = match("1234", rx_1);  
      auto captures = m.front;
      writefln("%s", captures);
    }
    version(A2)
    {
      auto rx_2 = regex(r"^([0-9])*(\d)");
      auto m2 = match("1234", rx_2);
      auto captures2 = m2.front;
      writefln("%s", captures2);
    }
    return 0;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #2 from Dmitry Olshansky <dmitry.olsh gmail.com> 2012-12-27
10:47:11 PST ---
https://github.com/D-Programming-Language/phobos/pull/1040
https://github.com/D-Programming-Language/phobos/pull/1041

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 27 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211



--- Comment #3 from github-bugzilla puremagic.com 2012-12-29 06:37:19 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/4a08974927ffd467ba05a20f42c72a5fbc500f71
fix issue 9211

A leftover from semantically incorrect optimization in std.regex

https://github.com/D-Programming-Language/phobos/commit/efb7a7b5100ea133ef68f5aa65f9e240f20672d4
Merge pull request #1040 from blackwhale/regex-bug9211

Regex bugfix (issue 9211). I assume FreeBSD's failure is unrelated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 29 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211



--- Comment #4 from github-bugzilla puremagic.com 2013-01-02 01:37:25 PST ---
Commit pushed to 2.061 at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/6ed2e15cf4a35e274adb8385b3ee8125326509f9
Merge pull request #1040 from blackwhale/regex-bug9211

Regex bugfix (issue 9211). I assume FreeBSD's failure is unrelated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211


Dmitry Olshansky <dmitry.olsh gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9211



--- Comment #5 from github-bugzilla puremagic.com 2013-01-02 10:25:36 PST ---
Commit pushed to staging at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/6ed2e15cf4a35e274adb8385b3ee8125326509f9
Merge pull request #1040 from blackwhale/regex-bug9211

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2013