From 184e45b7749cc78ce897df2bf30bf576fe9fe302 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Sun, 7 Aug 2016 06:28:17 -0700 Subject: [PATCH] Fix bug with tools/html-grep. We were ignoring singleton tags like "input" tags in html-grep. This was an artifact of our tokenizer originally being built to check indentation of templates, for which singleton tags had been a distraction. This fix actually cleans up the template checking logic as well, since it can now rely on the tokenizer to classify special tags and singleton tags. The tokenizer is more complete and more specific. --- tools/lib/template_parser.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/lib/template_parser.py b/tools/lib/template_parser.py index 2e83717351..e51181f2a3 100644 --- a/tools/lib/template_parser.py +++ b/tools/lib/template_parser.py @@ -66,7 +66,12 @@ def tokenize(text): if looking_at_html_start(): s = get_html_tag(text, state.i) tag = s[1:-1].split()[0] - kind = 'html_start' + if is_special_html_tag(s, tag): + kind = 'html_special' + elif s.endswith('/>'): + kind = 'html_singleton' + else: + kind = 'html_start' elif looking_at_html_end(): s = get_html_tag(text, state.i) tag = s[2:-1] @@ -171,11 +176,9 @@ def validate(fn=None, text=None, check_indent=True): for token in tokens: kind = token.kind tag = token.tag - s = token.s if kind == 'html_start': - if not is_special_html_tag(s, tag): - start_tag_matcher(token) + start_tag_matcher(token) elif kind == 'html_end': state.matcher(token) @@ -204,7 +207,6 @@ def validate(fn=None, text=None, check_indent=True): def is_special_html_tag(s, tag): # type: (str, str) -> bool return (s.startswith('