Skip to content

Fix tokens line number calculation when whitespace stripping is used#1178

Merged
davidism merged 1 commit intopallets:2.11.xfrom
avli:fix-lexer-lineno
Mar 30, 2020
Merged

Fix tokens line number calculation when whitespace stripping is used#1178
davidism merged 1 commit intopallets:2.11.xfrom
avli:fix-lexer-lineno

Conversation

@avli
Copy link
Copy Markdown
Contributor

@avli avli commented Mar 27, 2020

The current version seems to assign wrong line numbers to tokens when whitespace trimming is used. For example this code:

from jinja2 import Environment

if __name__ == '__main__':
    env = Environment()
    tmpl = env.from_string(
"""\
<html>
<body>
{%- block content -%}
    <hr>
    {{ item }}
{% endblock %}
</body>
</html>"""
    )
    print(tmpl.debug_info)

prints [(2, 12), (4, 23)] when it should be [(3, 12), (5, 23)]. In particular, this causes troubles for debuggers (see here).

The suggested patch attempts to fix the line number calculation. Please let me know if I have missed something. Thanks in advance!

@davidism davidism changed the base branch from master to 2.11.x March 30, 2020 18:11
@davidism davidism added this to the 2.11.2 milestone Mar 30, 2020
@davidism davidism merged commit 5f95471 into pallets:2.11.x Mar 30, 2020
@davidism
Copy link
Copy Markdown
Member

Thanks for the fix! This will be in 2.11.2.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants