File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -288,6 +288,10 @@ protected function lexComment(): void
288288 $ text = substr ($ this ->source , $ this ->cursor , $ matches [0 ][1 ] - $ this ->cursor );
289289
290290 $ this ->moveCursor ($ text .$ matches [0 ][0 ]);
291+
292+ if ($ matches [2 ][0 ][0 ] === LexerOptions::WhitespaceTrim->value ) {
293+ $ this ->trimWhitespaces ();
294+ }
291295 }
292296
293297 protected function lexInlineComment (): void
Original file line number Diff line number Diff line change @@ -116,10 +116,10 @@ public static function blockCommentDataRegex(): string
116116
117117 if ($ regex === null ) {
118118 $ regex = sprintf (
119- '{%s(%s)? \s*endcomment\s*(?:%s| %s)}sx ' ,
119+ '{(%s%s?) \s*endcomment\s*(%s? %s)}sx ' ,
120120 preg_quote (LexerOptions::TagBlockStart->value ),
121121 LexerOptions::WhitespaceTrim->value ,
122- preg_quote ( LexerOptions::WhitespaceTrim->value .LexerOptions::TagBlockEnd-> value ) ,
122+ LexerOptions::WhitespaceTrim->value ,
123123 preg_quote (LexerOptions::TagBlockEnd->value ),
124124 );
125125 }
Original file line number Diff line number Diff line change 488488 </div>
489489 HTML;
490490 assertTemplateResult ($ expected , $ source );
491+
492+ $ source = <<<'LIQUID'
493+ {%- comment -%}123{%- endcomment -%}Hello!
494+ LIQUID;
495+ assertTemplateResult ('Hello! ' , $ source );
496+
497+ $ source = <<<'LIQUID'
498+ {%- comment -%}123{%- endcomment -%} Hello!
499+ LIQUID;
500+ assertTemplateResult ('Hello! ' , $ source );
501+
502+ $ source = <<<'LIQUID'
503+ {%- comment -%}123{%- endcomment -%} Hello!
504+ LIQUID;
505+ assertTemplateResult ('Hello! ' , $ source );
506+
507+ $ source = <<<'LIQUID'
508+ {%- comment %}Whitespace control!{% endcomment -%}
509+ Hello!
510+ LIQUID;
511+ assertTemplateResult ('Hello! ' , $ source );
491512});
492513
493514test ('complex trim output ' , function () {
Original file line number Diff line number Diff line change 133133 $ tokens ->consume (TokenType::BlockEnd);
134134});
135135
136+ test ('[comment] whitespace trim ' , function () {
137+ expect (tokenize ('{%- comment -%}123{%- endcomment -%} Hello! ' )->consume ())
138+ ->type ->toBe (TokenType::TextData)
139+ ->data ->toBe ('Hello! ' );
140+
141+ expect (tokenize ("{%- comment -%}123{%- endcomment -%} \nHello! " )->consume ())
142+ ->type ->toBe (TokenType::TextData)
143+ ->data ->toBe ('Hello! ' );
144+ });
145+
146+ test ('[comment] without whitespace trim ' , function () {
147+ expect (tokenize ('{% comment %}123{% endcomment %} Hello! ' )->consume ())
148+ ->type ->toBe (TokenType::TextData)
149+ ->data ->toBe (' Hello! ' );
150+
151+ expect (tokenize ("{% comment %}123{% endcomment %} \nHello! " )->consume ())
152+ ->type ->toBe (TokenType::TextData)
153+ ->data ->toBe ("\nHello! " );
154+ });
155+
136156test ('text ' , function () {
137157 expect (tokenize (' ' )->consume ())
138158 ->type ->toBe (TokenType::TextData)
You can’t perform that action at this time.
0 commit comments