-
Notifications
You must be signed in to change notification settings - Fork 95
Fix gnarly bug in Node and SpaceInsideBraces #423
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow amazing! Thanks for putting in the work to make this part solid 🙏
Just a couple questions and suggestions.
output += "{{" if variable? | ||
output += "{%" if tag? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't be a variable & tag at the same time:
output += "{{" if variable? | |
output += "{%" if tag? | |
if variable? | |
output += "{{" | |
elsif tag? | |
output += "{%" | |
end |
Same bellow.
# Here we're hacking around a glorious bug in Liquid that makes it so the | ||
# line_number and markup of a tag is wrong if there's whitespace | ||
# between the tag_name and the markup of the tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a sense if this is fixable in Liquid, or is just the way it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be fixable but the way tags are created you don't really know. We'd need to somehow pass it in the parse_context since we lose the information on tag creation (the tag_name and markup come in as two separate variables)
Whoops! Actually found a tiny bug, checking Dawn:
|
So the location is wrong, but the error is correct!
There's a missing space here! |
b94e0a9
to
02d2633
Compare
contents.lines is a very expensive operation if you do it 100,000 times! This reimplements the function without being so careless about memory.
02d2633
to
c5475c5
Compare
Fixes #420
This fixes a LOT of bugs actually! This bug was like finding a little crack in a wall and then finding you have termites.
This is Liquid's
raw
output for the following tag:As you can see, not only do we not have the whitespace all the way till "render", we also don't have the whitespace between render and 'file'. This breaks all Position calculations since the needle does not exist in the source.
The implementation of
whitespace_trimmed?
didn't account for tags starting in the middle of a line. Or for tags starting on a different lineThe implementation of
whitespace_trimmed?
assumed that it was trimmed in pairs (start and end) when it's possible to do it independently.Similarly a lot of our logic for space before/after tokens was wrong inside SpaceInsideBraces
Our implementation of
inside_liquid_tag?
was flipped. The tests were wrong and the implementation was too!