What happened?
When using whitespace trim (-%}) on the {% endcomment %} tag, trailing whitespace and newlines are not removed as expected.
Expected behavior: {%- endcomment -%} should remove all trailing whitespace (spaces and newlines) from the output, matching the behavior of Shopify's official Liquid implementation and its tests.
Actual behavior: Trailing whitespace and newlines are preserved even when whitespace trim is specified.
How to reproduce the bug
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Keepsuit\Liquid\Environment;
$environment = Environment::default();
// Test 1: Trailing spaces are not trimmed
$template = "{%- comment -%}123{%- endcomment -%} Hello!";
$result = $environment->parseString($template)->render($environment->newRenderContext());
echo json_encode($result) . "\n";
// Expected: "Hello!"
// Actual: " Hello!"
// Test 2: Trailing newline is not trimmed
$template = "{%- comment -%}123{%- endcomment -%}\nHello!";
$result = $environment->parseString($template)->render($environment->newRenderContext());
echo json_encode($result) . "\n";
// Expected: "Hello!"
// Actual: "\nHello!"
For comparison, other tags like {% if %} work correctly:
// This works correctly
$template = "{%- if true -%}yes{%- endif -%}\nHello!";
$result = $environment->parseString($template)->render($environment->newRenderContext());
// Result: "yesHello!" (newline is trimmed)
Package Version
0.9.0
PHP Version
8.3.28
Which operating systems does with happen with?
Linux
What happened?
When using whitespace trim (
-%}) on the{% endcomment %}tag, trailing whitespace and newlines are not removed as expected.Expected behavior:
{%- endcomment -%}should remove all trailing whitespace (spaces and newlines) from the output, matching the behavior of Shopify's official Liquid implementation and its tests.Actual behavior: Trailing whitespace and newlines are preserved even when whitespace trim is specified.
How to reproduce the bug
For comparison, other tags like
{% if %}work correctly:Package Version
0.9.0
PHP Version
8.3.28
Which operating systems does with happen with?
Linux