-
-
Notifications
You must be signed in to change notification settings - Fork 172
Open
Description
Hi, during my migration from jtwig to pebble I've noticed some odd behaviour: sometimes newlines are trimmed. Here is a test case to reproduce the issue:
import com.mitchellbosecke.pebble.PebbleEngine
import org.junit.jupiter.api.Test
import java.io.StringWriter
import java.io.Writer
class PebbleTest {
val template = """
<!DOCTYPE html>
<html>
<script>
const foo = {{ foo | default("null") }}
const bar = {{ bar | default("null") }};
</script>
</html>
""".trimIndent()
@Test
fun `no newline`() {
val pebble = PebbleEngine.Builder().build()
val template = pebble.getLiteralTemplate(template)
val writer: Writer = StringWriter()
template.evaluate(writer)
println(writer.toString())
}
}
What I expect is:
<!DOCTYPE html>
<html>
<script>
const foo = null
const bar = null;
</script>
</html>
But what I get is:
<!DOCTYPE html>
<html>
<script>
const foo = null const bar = null;
</script>
</html>
It seems that the presence of the ; after the const bar definition means a semicolon will be inserted correctly. If I add one to the end of the const foo line the program behaves correctly.
(It's probably invalid JS to skip the semicolons... my fix was just to insert them. But the behaviour seemed unexpected to me!)
Metadata
Metadata
Assignees
Labels
No labels