mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Do not use cached results for regexes that contain \G.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user