Skip to content

Commit

Permalink
Merge pull request #5250 from DmitryOlshansky/isssue-17157
Browse files Browse the repository at this point in the history
Fix issue 17157 ctRegex.matchAll doesn't set last item in Captures
  • Loading branch information
andralex committed Mar 9, 2017
2 parents 694dd17 + 0e76847 commit 7200b36
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions std/regex/internal/backtracking.d
Expand Up @@ -277,6 +277,7 @@ template BacktrackingMatcher(bool CTregex)
pc = 0;
counter = 0;
lastState = 0;
matches[] = Group!DataIndex.init;
auto start = s._index;
debug(std_regex_matcher)
writeln("Try match starting at ", s[index..s.lastIndex]);
Expand Down Expand Up @@ -1439,6 +1440,7 @@ struct CtContext
pc = 0;
counter = 0;
lastState = 0;
matches[] = Group!DataIndex.init;
auto start = s._index;`;
r ~= `
goto StartLoop;
Expand Down
17 changes: 17 additions & 0 deletions std/regex/internal/tests.d
Expand Up @@ -1056,3 +1056,20 @@ unittest
auto r = regex(" [a] ", "x");
assert("a".matchFirst(r));
}

// bugzilla 17157
@safe unittest
{
import std.algorithm.comparison : equal;
auto ctr = ctRegex!"(a)|(b)|(c)|(d)";
auto r = regex("(a)|(b)|(c)|(d)", "g");
auto s = "--a--b--c--d--";
auto outcomes = [
["a", "a", "", "", ""],
["b", "", "b", "", ""],
["c", "", "", "c", ""],
["d", "", "", "", "d"]
];
assert(equal!equal(s.matchAll(ctr), outcomes));
assert(equal!equal(s.bmatch(r), outcomes));
}

0 comments on commit 7200b36

Please sign in to comment.