Bug 9211 – regex lookahead, (?=(\d\d\d)+\b) failed

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-26T14:13:00Z
Last change time
2013-01-02T10:25:36Z
Keywords
pull
Assigned to
nobody
Creator
p.summerland

Comments

Comment #0 by p.summerland — 2012-12-26T14:13:35Z
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
Comment #1 by dmitry.olsh — 2012-12-27T08:15:19Z
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; }
Comment #2 by dmitry.olsh — 2012-12-27T10:47:11Z
Comment #3 by github-bugzilla — 2012-12-29T06:37:19Z
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.
Comment #4 by github-bugzilla — 2013-01-02T01:37:25Z
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.
Comment #5 by github-bugzilla — 2013-01-02T10:25:36Z