fix highlighting hang with empty begin end rules

This commit is contained in:
Anthony Sottile
2020-07-24 15:13:35 -07:00
parent 33ff8d9726
commit 84b20a4016
2 changed files with 40 additions and 5 deletions

View File

@@ -637,3 +637,25 @@ def test_backslash_z(compiler_state):
assert regions2 == (
Region(0, 6, ('test', 'comment')),
)
def test_buggy_begin_end_grammar(compiler_state):
# before this would result in an infinite loop of start / end
compiler, state = compiler_state({
'scopeName': 'test',
'patterns': [
{
'begin': '(?=</style)',
'end': '(?=</style)',
'name': 'css',
},
],
})
state, regions = highlight_line(compiler, state, 'test </style', True)
assert regions == (
Region(0, 5, ('test',)),
Region(5, 6, ('test', 'css')),
Region(6, 12, ('test',)),
)