Do not use cached results for regexes that contain \G.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-10-22 11:04:20 -07:00
parent 2635631d81
commit fcbbe0a29b
2 changed files with 10 additions and 2 deletions

View File

@@ -56,8 +56,11 @@ class OnigScannerUserData : public CefBase {
bool useCachedResult = false;
OnigResult *result = NULL;
if (useCachedResults && index <= maxCachedIndex) {
// In Oniguruma, \G is based on the start position of the match, so the result
// changes based on the start position. So it can't be cached.
BOOL containsBackslashG = [regExp.expression rangeOfString:@"\\G"].location != NSNotFound;
if (useCachedResults && index <= maxCachedIndex && ! containsBackslashG) {
result = cachedResults[index];
useCachedResult = (result == NULL || [result locationAt:0] >= startLocation);
}

View File

@@ -239,3 +239,8 @@ describe "TextMateGrammar", ->
expect(tokens.length).toBe 2
expect(tokens[0].value).toBe "//"
expect(tokens[1].value).toBe " a singleLineComment"
it "does not loop infinitley (regression)", ->
grammar = TextMateBundle.grammarForFileName("hello.js")
{tokens, stack} = grammar.getLineTokens("// line comment")
{tokens, stack} = grammar.getLineTokens(" // second line comment with a single leading space", stack)