From b5a674d94170d4e9ee9a67080fc8223b38b04a05 Mon Sep 17 00:00:00 2001 From: Robert Raposa Date: Tue, 12 Apr 2016 15:18:37 -0400 Subject: [PATCH] Fix parsing defect --- scripts/safe_template_linter.py | 13 ++++++++++--- scripts/tests/test_safe_template_linter.py | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/safe_template_linter.py b/scripts/safe_template_linter.py index 8ab696bc31..d2456c2fea 100755 --- a/scripts/safe_template_linter.py +++ b/scripts/safe_template_linter.py @@ -874,8 +874,8 @@ class MakoTemplateLinter(object): filters = filters_match.group()[1:-1].replace(" ", "").split(",") if (len(filters) == 2) and (filters[0] == 'n') and (filters[1] == 'unicode'): - # {x | n, unicode} is valid in any context - pass + # {x | n, unicode} is valid in any context + pass elif context == 'html': if (len(filters) == 1) and (filters[0] == 'h'): if has_page_default: @@ -1053,7 +1053,14 @@ class MakoTemplateLinter(object): open_char_index = template.find(open_char, start_index, close_char_index) parse_string = ParseString(template, start_index, close_char_index) + valid_index_list = [close_char_index] + if 0 <= open_char_index: + valid_index_list.append(open_char_index) if 0 <= parse_string.start_index: + valid_index_list.append(parse_string.start_index) + min_valid_index = min(valid_index_list) + + if parse_string.start_index == min_valid_index: strings.append(parse_string) if parse_string.end_index < 0: return unparseable_result @@ -1063,7 +1070,7 @@ class MakoTemplateLinter(object): num_open_chars=num_open_chars, strings=strings ) - if 0 <= open_char_index < close_char_index: + if open_char_index == min_valid_index: if start_delim is not None: # if we find another starting delim, consider this unparseable start_delim_index = template.find(start_delim, start_index, close_char_index) diff --git a/scripts/tests/test_safe_template_linter.py b/scripts/tests/test_safe_template_linter.py index 8164d42b51..da68230101 100644 --- a/scripts/tests/test_safe_template_linter.py +++ b/scripts/tests/test_safe_template_linter.py @@ -247,6 +247,10 @@ class TestMakoTemplateLinter(TestCase): 'expression': "${ HTML('') }", 'rule': None }, + { + 'expression': "${HTML(render_entry(map['entries'], child))}", + 'rule': None + }, { 'expression': "${ HTML('') + 'some other text' }", 'rule': Rules.mako_html_alone