Skip to content

Commit

Permalink
Fix a regex bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rajatd committed Jun 21, 2017
1 parent 7c1da39 commit a8e157a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Parser/RegexRuntime.cpp
Expand Up @@ -4286,10 +4286,17 @@ namespace UnifiedRegex
else
{
// Backtrack to the previous offset where we matched the LoopSet's followFirst
// We will be doing one unnecessary match. But, if we wanted to avoid it, we'd have
// to propagate to the next Inst, that the first character is already matched.
// Seems like an overkill to avoid one match.
loopInfo->number = loopInfo->offsetsOfFollowFirst->RemoveAtEnd();
}
}

// If loopInfo->number now is less than begins->repeats.lower, the loop
// shouldn't match anything. In that case, stop backtracking.
loopInfo->number = max(loopInfo->number, begin->repeats.lower);

// Rewind input
inputOffset = loopInfo->startInputOffset + loopInfo->number;

Expand Down
3 changes: 3 additions & 0 deletions test/Regex/regex1.baseline
Expand Up @@ -21,3 +21,6 @@ lastIndex test 5 passed
lastIndex test 6 passed
lastIndex test 7 passed
aa,a,a
null
null
null
5 changes: 5 additions & 0 deletions test/Regex/regex1.js
Expand Up @@ -148,4 +148,9 @@ c=[/[\300-\306]/g,"A",/[\340-\346]/g,"a",/\307/g,"C",/\347/g,"c",/[\310-\313]/g,
//Negation of empty char set [^] test
write("aa".match(/([^])(\1)/));

write(/^.+ ab/g.exec(" ab"))
write(/^.+a /.exec("a "))
write(/^.+ax/.exec("ax"))



0 comments on commit a8e157a

Please sign in to comment.