Protect against nameless HTML tags in tools/lib/template_parser.py.

Fixed IndexError when there is only zero or more whitespace characters
between < and >. (str.split() will return an empty list in this case, which
means there is no index 0.)
This commit is contained in:
Gordon P. Hemsley 2016-08-30 18:54:41 -04:00
parent c9d1a4247f
commit 2e865f03bf
2 changed files with 14 additions and 1 deletions

View File

@ -69,7 +69,13 @@ def tokenize(text):
while state.i < len(text): while state.i < len(text):
if looking_at_html_start(): if looking_at_html_start():
s = get_html_tag(text, state.i) s = get_html_tag(text, state.i)
tag = s[1:-1].split()[0] tag_parts = s[1:-1].split()
if not tag_parts:
raise TemplateParserException("Tag name missing")
tag = tag_parts[0]
if is_special_html_tag(s, tag): if is_special_html_tag(s, tag):
kind = 'html_special' kind = 'html_special'
elif s.endswith('/>'): elif s.endswith('/>'):

View File

@ -127,6 +127,13 @@ class ParserTest(unittest.TestCase):
''' '''
self._assert_validate_error('Tag missing >', text=my_html) self._assert_validate_error('Tag missing >', text=my_html)
def test_validate_empty_html_tag(self):
# type: () -> None
my_html = '''
< >
'''
self._assert_validate_error('Tag name missing', text=my_html)
def test_code_blocks(self): def test_code_blocks(self):
# type: () -> None # type: () -> None