summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-07-12 14:42:31 +0200
committerJo-Philipp Wich <jo@mein.io>2022-07-12 14:44:12 +0200
commitfd433aa285ff2b4f6270d6993d1b258ad48af36e (patch)
tree527e07a1b032512497b3448c7e6be360de3c27ec
parent35c6b73c347caf45d74431890c1885ef58bfae24 (diff)
lexer: fix parsing with disabled block left stripping
When a template was parsed with global block left stripping disabled, then any text preceding an expression or statement block start tag was incorrectly prepended to the first token value of the block, leading to syntax errors in the compiler. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lexer.c9
-rw-r--r--tests/custom/04_bugs/40_lexer_bug_on_lstrip_off20
2 files changed, 26 insertions, 3 deletions
diff --git a/lexer.c b/lexer.c
index aae3e2f..5be8ece 100644
--- a/lexer.c
+++ b/lexer.c
@@ -887,9 +887,12 @@ lex_step(uc_lexer_t *lex, FILE *fp)
buf_consume(lex, 1);
}
- /* global block lstrip */
- else if (lex->config && lex->config->lstrip_blocks) {
- rv = lookbehind_to_text(lex, lex->source->off, TK_TEXT, " \t\v\f\r");
+ /* put out text leading up to the opening tag and potentially
+ * strip trailing white space from it depending on the global
+ * block lstrip setting */
+ else {
+ rv = lookbehind_to_text(lex, lex->source->off, TK_TEXT,
+ (lex->config && lex->config->lstrip_blocks) ? " \t\v\f\r" : NULL);
}
}
else {
diff --git a/tests/custom/04_bugs/40_lexer_bug_on_lstrip_off b/tests/custom/04_bugs/40_lexer_bug_on_lstrip_off
new file mode 100644
index 0000000..dc4f8dd
--- /dev/null
+++ b/tests/custom/04_bugs/40_lexer_bug_on_lstrip_off
@@ -0,0 +1,20 @@
+When a template was parsed with global block left stripping disabled,
+then any text preceding an expression or statement block start tag was
+incorrectly prepended to the first token value of the block, leading
+to syntax errors in the compiler.
+
+-- Testcase --
+{% for (let x in [1, 2, 3]): %}
+{{ x }}
+{% endfor %}
+-- End --
+
+-- Args --
+-Tno-lstrip
+-- End --
+
+-- Expect stdout --
+1
+2
+3
+-- End --