@@ -22,11 +22,13 @@ class AbstractBlock extends AbstractTag
22
22
const TAG_PREFIX = '\Liquid\Tag\Tag ' ;
23
23
24
24
/**
25
- * @var AbstractTag[]
25
+ * @var AbstractTag[]|Variable[]|string[]
26
26
*/
27
27
protected $ nodelist = array ();
28
28
29
29
/**
30
+ * Whenever next token should be ltrim'med.
31
+ *
30
32
* @var bool
31
33
*/
32
34
protected static $ trimWhitespace = false ;
@@ -92,6 +94,7 @@ public function parse(array &$tokens)
92
94
$ this ->whitespaceHandler ($ token );
93
95
$ this ->nodelist [] = $ this ->createVariable ($ token );
94
96
} else {
97
+ // This is neither a tag or a variable, proceed with an ltrim
95
98
if (self ::$ trimWhitespace ) {
96
99
$ token = ltrim ($ token );
97
100
}
@@ -109,16 +112,24 @@ public function parse(array &$tokens)
109
112
*
110
113
* @param string $token
111
114
*/
112
- protected function whitespaceHandler (& $ token )
115
+ protected function whitespaceHandler ($ token )
113
116
{
117
+ /*
118
+ * This assumes that TAG_START is always '{%', and a whitespace control indicator
119
+ * is exactly one character long, on a third position.
120
+ */
114
121
if (mb_substr ($ token , 2 , 1 ) === Liquid::get ('WHITESPACE_CONTROL ' )) {
115
122
$ previousToken = end ($ this ->nodelist );
116
- if (is_string ($ previousToken )) {
123
+ if (is_string ($ previousToken )) { // this can also be a tag or a variable
117
124
$ this ->nodelist [key ($ this ->nodelist )] = rtrim ($ previousToken );
118
125
}
119
126
}
120
127
121
- self ::$ trimWhitespace = (mb_substr ($ token , -3 , 1 ) === Liquid::get ('WHITESPACE_CONTROL ' ));
128
+ /*
129
+ * This assumes that TAG_END is always '%}', and a whitespace control indicator
130
+ * is exactly one character long, on a third position from the end.
131
+ */
132
+ self ::$ trimWhitespace = mb_substr ($ token , -3 , 1 ) === Liquid::get ('WHITESPACE_CONTROL ' );
122
133
}
123
134
124
135
/**
0 commit comments