diff --git a/src/main/java/com/hubspot/jinjava/tree/TreeParser.java b/src/main/java/com/hubspot/jinjava/tree/TreeParser.java index 8bdc29653..9904e7c7a 100644 --- a/src/main/java/com/hubspot/jinjava/tree/TreeParser.java +++ b/src/main/java/com/hubspot/jinjava/tree/TreeParser.java @@ -170,14 +170,17 @@ private Node getLastSibling() { private Node text(TextToken textToken) { if (interpreter.getConfig().isLstripBlocks()) { - if (scanner.hasNext() && scanner.peek().getType() == symbols.getTag()) { - textToken = - new TextToken( - StringUtils.stripEnd(textToken.getImage(), "\t "), - textToken.getLineNumber(), - textToken.getStartPosition(), - symbols - ); + if (scanner.hasNext()) { + final int nextTokenType = scanner.peek().getType(); + if (nextTokenType == symbols.getTag() || nextTokenType == symbols.getNote()) { + textToken = + new TextToken( + StringUtils.stripEnd(textToken.getImage(), "\t "), + textToken.getLineNumber(), + textToken.getStartPosition(), + symbols + ); + } } } diff --git a/src/main/java/com/hubspot/jinjava/tree/parse/TokenScanner.java b/src/main/java/com/hubspot/jinjava/tree/parse/TokenScanner.java index 54671d644..c336969d3 100644 --- a/src/main/java/com/hubspot/jinjava/tree/parse/TokenScanner.java +++ b/src/main/java/com/hubspot/jinjava/tree/parse/TokenScanner.java @@ -253,13 +253,18 @@ private Token newToken(int kind) { lastStart - lastNewlinePos + 1 ); - if (t instanceof TagToken) { - if (config.isTrimBlocks() && currPost < length && is[currPost] == '\n') { - lastNewlinePos = currPost; - ++currPost; - ++tokenStart; - } + if ( + (t instanceof TagToken || t instanceof NoteToken) && + config.isTrimBlocks() && + currPost < length && + is[currPost] == '\n' + ) { + lastNewlinePos = currPost; + ++currPost; + ++tokenStart; + } + if (t instanceof TagToken) { TagToken tt = (TagToken) t; if ("raw".equals(tt.getTagName())) { inRaw = 1; diff --git a/src/test/java/com/hubspot/jinjava/tree/TreeParserTest.java b/src/test/java/com/hubspot/jinjava/tree/TreeParserTest.java index d1522b23b..c54a33735 100644 --- a/src/test/java/com/hubspot/jinjava/tree/TreeParserTest.java +++ b/src/test/java/com/hubspot/jinjava/tree/TreeParserTest.java @@ -147,6 +147,18 @@ public void trimAndLstripBlocks() { .isEqualTo("