Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trim] Fix trimming at end of raw block when specified in the opening tag #1717

Merged
merged 1 commit into from May 19, 2023

Conversation

gmalette
Copy link
Contributor

The raw tag doesn't use BlockBody to parse its body. As a result, it currently doesn't respect nor reset the parsing context's trim_whitespace value.

This PR makes it reset it at the end of the block, respecting either non-trimming (endraw %}) or trimming (endraw -%}).

This change is in line with Liquid::C's implementation.

It does not respect inner whitespace control, and {% raw -%} inner {%- endraw %} will preserve the spaces. This is also in line with Liquid::C.

@@ -26,6 +26,7 @@ def parse(tokens)
@body = +''
while (token = tokens.shift)
if token =~ FullTokenPossiblyInvalid && block_delimiter == Regexp.last_match(2)
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always reset this in the next tag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do when using block_body and encountering a {% ... token. I can't say for certain if all block tags use BlockBody, although it looks that way (except raw).

@gmalette gmalette merged commit 42e5c52 into master May 19, 2023
10 checks passed
@gmalette gmalette deleted the gm/fix-raw-trimmode-at-end-of-block branch May 19, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants