Skip to content

Commit 30759a5

Browse files
committed
Escaping special closing character ] does not work fix #611
1 parent 42626c0 commit 30759a5

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

handlebars/src/main/antlr4/com/github/jknack/handlebars/internal/HbsLexer.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ ID_SUFFIX
348348
fragment
349349
ID_ESCAPE
350350
:
351-
'[' ~[\]]+? ']'
351+
'[' ('\\]' | ~[\]])+? ']'
352352
;
353353
354354
fragment
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.jknack.handlebars.issues;
2+
3+
import com.github.jknack.handlebars.v4Test;
4+
import org.junit.Test;
5+
6+
public class Issue611 extends v4Test {
7+
8+
@Test
9+
public void shouldScapeRightBracket() throws Exception {
10+
shouldCompileTo("<div class=\"entry\">\n"
11+
+ " <h1>{{ fields.[Special [case\\]] }}</h1>\n"
12+
+ "</div>", $("hash", $("fields", $("Special [case\\]", "yo"))), "<div class=\"entry\">\n"
13+
+ " <h1>yo</h1>\n"
14+
+ "</div>");
15+
}
16+
}

handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue614.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class Issue614 extends v4Test {
88

99
@Test
10-
public void shouldFavorIntOverDouble() throws Exception {
10+
public void shouldGetTextFromElseIf() throws Exception {
1111
String text = compile("{{#if a}}a{{else if b}}b{{else}}c{{/if}}").text();
1212
assertEquals("{{#if a}}a{{else if b}}b{{else}}c{{/if}}", text);
1313
}

0 commit comments

Comments
 (0)