Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/main/java/com/hubspot/jinjava/tree/parse/TokenScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,15 @@ private Token getNextToken() {
}

if (inBlock > 0) {
if (inQuote != 0) {
if (c == '\\') {
++currPost;
continue;
} else if (inQuote != 0) {
if (inQuote == c) {
inQuote = 0;
continue;
} else if (c == '\\') {
++currPost;
continue;
} else {
continue;
}
} else if (inQuote == 0 && (c == '\'' || c == '"')) {
continue;
} else if (c == '\'' || c == '"') {
inQuote = c;
continue;
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/com/hubspot/jinjava/tree/parse/TokenScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ public void testLstripBlocks() {
assertThat(tokens).isNotEmpty();
}

@Test
public void itTreatsEscapedQuotesSameWhenNotInQuotes() {
List<Token> tokens = tokens("tag-with-all-escaped-quotes");
assertThat(tokens).hasSize(8);
assertThat(tokens.stream().map(Token::getType).collect(Collectors.toList()))
.containsExactly(
symbols.getNote(),
symbols.getFixed(),
symbols.getTag(),
symbols.getFixed(),
symbols.getTag(),
symbols.getFixed(),
symbols.getTag(),
symbols.getFixed()
);
}

private List<Token> tokens(String fixture) {
TokenScanner t = fixture(fixture);
return Lists.newArrayList(t);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{# This print tag is invalid, but it should not cause the rest of the template to break #}
{% print \"foo\" %}
Start
{% if true %}
The dog says: "Woof!"
{% endif %}
End