Skip to content

Fix raw closing tags immediately after a variable opener - #2127

Open
mehuljariwala wants to merge 2 commits into
Shopify:mainfrom
mehuljariwala:fix/raw-end-delimiter
Open

mehuljariwala wants to merge 2 commits into
Shopify:mainfrom
mehuljariwala:fix/raw-end-delimiter

Conversation

@mehuljariwala

Copy link
Copy Markdown

Problem

When a raw block contains {{% endraw %}}, the tokenizer consumes the closing tag together with the trailing brace as a variable token. The raw parser cannot recognize the delimiter, so it either reports an unclosed block or swallows a later raw block.

For example, {%raw%}%{{%endraw%}}{%raw%}x{%endraw%} currently renders %{{%endraw%}}{%raw%}x; with this change it renders %{}x.

Fixes #2124.

Change

Recognize an endraw tag beginning at the second brace of a variable-start token, including whitespace-control markers, and stop the token at %}. The existing raw parser can then consume the delimiter and leave trailing braces to render as text. The lookahead is limited to endraw so malformed variables such as {{%%%}} retain their existing error handling.

Regression coverage checks adjacent raw blocks, multiple trailing braces, and whitespace control followed by a rendered variable. The new test fails on the original revision and passes with the fix. No dependencies added.

Validation

Ruby 4.0.6 on macOS arm64, upstream base 4e39ae4cc3da73921923c0669e0fc84a66b2f696:

  • bundle exec ruby -Itest test/integration/tags/raw_tag_test.rb: 5 tests, 26 assertions, no failures.
  • bundle exec rake: all three parser modes passed. Each full-suite pass ran 1,063 tests / 2,544 assertions; each additional integration pass ran 803 tests / 1,919 assertions. RuboCop inspected 160 files with no offenses.
  • git diff --check: passed.
  • PHASE=tokenize bundle exec ruby performance/benchmark.rb lax: upstream 2.070k iterations/s (±0.9%); patched 2.072k iterations/s (±0.9%). Each used the repository benchmark's 10-second warmup and 20-second measurement with YJIT enabled. These local runs executed concurrently, so this is a coarse comparison; no measurable regression was observed within their reported variability.

The suite emits existing Ruby 4 CGI-removal and RuboCop plugin-migration warnings. No live Shopify service or browser interaction is needed for this parser change. The broader tokenizer rewrite in #2071 touches the same module; this PR provides a focused fix and regression coverage for the current implementation.

AI assistance

OpenAI Codex assisted with reproduction, implementation, and execution of the tests and benchmarks above. No independent human review is claimed. Any CLA acceptance must be completed by the contributor personally.

@mehuljariwala

Copy link
Copy Markdown
Author

I have signed the CLA!

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

CLA: Unexpected error has occurred, please re-run the workflow.

We are sorry for the inconvenience, due to GitHub actions limitations this requires a manual intervention.

There are few ways to do it:

  • Create a new pull request with the same changes.
  • Push an empty commit to the branch.
  • Rebase the branch on top of the latest master might also help.

If the issue persists, please contact the maintainers of this repo.

This branch has not been deployed

No deployments
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.

{% raw %} does not close at the first {% endraw %} when its body contains {{

1 participant