feat(lexer): include the offending tag in newline errors - #379
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
A newline inside a {{ }} or {% %} reported "Newline not allowed within
tag/variable." with no hint of which tag, which is hard to locate in a
large template. Quote the offending tag/variable in the message instead,
e.g. Newline not allowed within tag/variable: "{{test\n}}".
The lexer now remembers where the current tag opened, since start moves
forward as inner tokens are emitted. The snippet spans the opening
delimiter to the first closing one and is length-capped so an
unterminated tag can't flood the message.
Closes flosch#185
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #185.
When a template has a newline inside a
{{ }}or{% %}, the lexer reportsNewline not allowed within tag/variable.with no hint of which tag it was, which is a pain to track down in a large template. This appends the offending tag/variable to the message, quoted so the newline stays on a single line:To do that the lexer remembers where the current tag opened (
tagStart), sincestartkeeps moving forward as inner tokens are emitted. The snippet runs from the opening delimiter to the first closing one, and it's length-capped so an unterminated tag can't blow up the error message.Added a regression test in
pongo2_issues_test.gocovering a variable, a tag, and an unterminated tag. Happy to adjust the exact format if you'd prefer something else.