Skip to content

Error parsing Django with unclosed tag inside if statement #14

@adamghill

Description

@adamghill

Describe the bug

Running curlylint on the following example Django template throws an exception. It appears that having an un-closed tag inside of the if statement causes an issue for curlylint. While probably not a great practice (there are other ways to achieve the same result) it came as a surprise that it wouldn't even parse it.

{% for thing in things %}
	{% if forloop.first %}
	<ul>
	{% endif %}

	<li>{{ thing }}</li>
	
	{% if forloop.last %}
	</ul>
	{% endif %}
{% endfor %}

Which terms did you search for in the documentation and issue tracker?

I looked through all of the open and closed issues.

Environment

Python 3.6.6
curlylint 0.12.0

Steps to reproduce

  1. First, create a template with the above example.
  2. Then, run curlylint pointing to the template created.

Expected behavior

Parse and lint the template without throwing an exception.

Actual behavior

Exception thrown:

  File ".venv/lib/python3.6/site-packages/parsy/__init__.py", line 275, in seq_parser
    result = parser(stream, index).aggregate(result)
  File ".venv/lib/python3.6/site-packages/parsy/__init__.py", line 80, in __call__
    return self.wrapped_fn(stream, index)
  File ".venv/lib/python3.6/site-packages/parsy/__init__.py", line 338, in generated
    next_parser = iterator.send(value)
  File ".venv/lib/python3.6/site-packages/curlylint/parse.py", line 541, in opt_container_impl
    yield P.fail("expected `{% if " + content + " %}`")
TypeError: must be str, not Parser

Reproducible demo

I can fork this repo and add a sample template to the tests directory if that is helpful. Or create a minimal repo demonstrating the issue. Let me know which might be the most useful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparserThis issue relates to Curlylint’s templates parser

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions