Skip to content

End an unclosed block in {% liquid %} at its last line - #1357

Merged
clauderic merged 1 commit into
mainfrom
liquid-unclosed-block-end
Oct 23, 2026
Merged

clauderic merged 1 commit into
mainfrom
liquid-unclosed-block-end

Conversation

@clauderic

@clauderic clauderic commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

What are you adding in this PR?

When unclosed blocks are allowed, as in toLiquidAST and the tolerant parses, a block in {% liquid %} that's never closed got the position of an end tag after its last line:

{%- liquid
  assign var1 = product
  if use_variant
    assign var2 = var1
-%}
  • The if's blockEndPosition started at the end of the last line and ran for the length of endif, over \n-%} and one character past the end of the 78-character template. Its position ended there too.
  • Inside an element, it ran over whatever came next. In <div>{% liquid … %}</div>, it covered \n%}</d.
  • It's now empty, at the end of the last line, as for an unclosed block outside {% liquid %}. The if covers if use_variant to var1.
  • A closed block is unchanged.

The test of this template now checks where the if ends. Every other test passes unchanged, and prettier formats these templates the same as before.

What's next? Any followup issues?

#1347 is stacked on this. #1359, the parser specs, on top of #1347, needs this fix: a spec gives a position as the text it covers, cut out of the template, and this one ran past its end.

Tophatting

  • npx vitest run packages/liquid-html-parser/src/document/parser.test.ts
  • Or: toLiquidAST the template above. Before, children[0].markup[1].blockEndPosition was { start: 74, end: 79 }; now it's { start: 74, end: 74 }.

Before you deploy

  • I included a patch bump changeset
  • My feature is backward compatible

🤖 Generated with Claude Code

With allowUnclosedDocumentNode, a block in {% liquid %} that's never
closed was given the position of an end tag at the end of the last
line: blockEndPosition ran from there for the length of "end" and the
tag name, so it and the block's position went past the end of the
template.

It's now empty, at the end of the last line, as for an unclosed block
outside {% liquid %}.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clauderic
clauderic requested a review from a team as a code owner October 21, 2026 00:24
@clauderic
clauderic added this pull request to stack #1358 October 21, 2026 00:29
@clauderic
clauderic removed this pull request from stack #1358 October 21, 2026 00:47
@clauderic
clauderic added this pull request to stack #1360 October 21, 2026 00:48
@clauderic
clauderic merged commit 6f7d7b0 into main Oct 23, 2026
8 checks passed
@clauderic
clauderic deleted the liquid-unclosed-block-end branch October 23, 2026 14:09
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.

2 participants