Fix escapes in conditional tabstob transformation

check if the delimiters :, (, and ) are actually escaped, not
only if the previous char is a backslash
This commit is contained in:
marius 2016-02-20 15:30:54 +01:00
parent ed40bebabf
commit 8fdfde1905

View File

@ -13,15 +13,20 @@ from UltiSnips.text_objects._mirror import Mirror
def _find_closing_brace(string, start_pos): def _find_closing_brace(string, start_pos):
"""Finds the corresponding closing brace after start_pos.""" """Finds the corresponding closing brace after start_pos."""
bracks_open = 1 bracks_open = 1
escaped = False
for idx, char in enumerate(string[start_pos:]): for idx, char in enumerate(string[start_pos:]):
if char == '(': if char == '(':
if string[idx + start_pos - 1] != '\\': if not escaped:
bracks_open += 1 bracks_open += 1
elif char == ')': elif char == ')':
if string[idx + start_pos - 1] != '\\': if not escaped:
bracks_open -= 1 bracks_open -= 1
if not bracks_open: if not bracks_open:
return start_pos + idx + 1 return start_pos + idx + 1
if char == '\\':
escaped = not escaped
else:
escaped = False
def _split_conditional(string): def _split_conditional(string):
@ -29,18 +34,24 @@ def _split_conditional(string):
bracks_open = 0 bracks_open = 0
args = [] args = []
carg = '' carg = ''
escaped = False
for idx, char in enumerate(string): for idx, char in enumerate(string):
if char == '(': if char == '(':
if string[idx - 1] != '\\': if not escaped:
bracks_open += 1 bracks_open += 1
elif char == ')': elif char == ')':
if string[idx - 1] != '\\': if not escaped:
bracks_open -= 1 bracks_open -= 1
elif char == ':' and not bracks_open and not string[idx - 1] == '\\': elif char == ':' and not bracks_open and not escaped:
args.append(carg) args.append(carg)
carg = '' carg = ''
escaped = False
continue continue
carg += char carg += char
if char == '\\':
escaped = not escaped
else:
escaped = False
args.append(carg) args.append(carg)
return args return args