Skip to content

Commit 6b61dbf

Browse files
authored
Merge pull request #623 from HubSpot/trim-quote-check
Trim before checking if expression is quoted
2 parents 76efb34 + 2d835e1 commit 6b61dbf

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/main/java/com/hubspot/jinjava/util/WhitespaceUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public static boolean isExpressionQuoted(String s) {
6161
if (Strings.isNullOrEmpty(s)) {
6262
return false;
6363
}
64-
char[] charArray = s.toCharArray();
64+
char[] charArray = s.trim().toCharArray();
65+
if (charArray.length == 1) {
66+
return false;
67+
}
6568
char quoteChar = 0;
6669
for (char c : QUOTE_CHARS) {
6770
if (charArray[0] == c) {

src/test/java/com/hubspot/jinjava/util/WhitespaceUtilsTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,17 @@ public void itKnowsWhenAnExpressionIsQuoted() {
4949
assertThat(isExpressionQuoted("\"foo 'and' bar\"")).isTrue();
5050
assertThat(isExpressionQuoted("\"foo 'and' bar'")).isFalse();
5151
}
52+
53+
@Test
54+
public void itKnowsUntrimmedExpressionIsQuoted() {
55+
assertThat(isExpressionQuoted(" 'foo'")).isTrue();
56+
assertThat(isExpressionQuoted("'foo' ")).isTrue();
57+
assertThat(isExpressionQuoted(" 'foo' ")).isTrue();
58+
}
59+
60+
@Test
61+
public void itDoesntCountSingleQuoteChar() {
62+
assertThat(isExpressionQuoted("'")).isFalse();
63+
assertThat(isExpressionQuoted("\" ")).isFalse();
64+
}
5265
}

0 commit comments

Comments
 (0)