noahmorrison / chevron

A Python implementation of mustache
MIT License
480 stars 52 forks source link

Tokenizing `{{}}` results in an IndexError #102

Open jeking3 opened 2 years ago

jeking3 commented 2 years ago

The tag parser is looking for content on an empty string.

>>> from chevron.tokenizer import tokenize
>>> print(list(tokenize(r"{{ foo }}")))
[('variable', 'foo')]
>>> print(list(tokenize(r"{{foo}}")))
[('variable', 'foo')]
>>> print(list(tokenize(r"{{ }}")))
[('variable', '')]
>>> print(list(tokenize(r"{{}}")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.../.tox/run/lib/python3.9/site-packages/chevron/tokenizer.py", line 190, in tokenize
    tag, template = parse_tag(template, l_del, r_del)
  File "/home/.../.tox/run/lib/python3.9/site-packages/chevron/tokenizer.py", line 89, in parse_tag
    tag_type = tag_types.get(tag[0], 'variable')
IndexError: string index out of range