Skip to content

Commit b4a363e

Browse files
committed
Allow carriage return and tabs. fix #699
1 parent 3b3bb67 commit b4a363e

2 files changed

Lines changed: 18 additions & 1 deletion

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
@@ -337,7 +337,7 @@ ID
337337
fragment
338338
ID_START
339339
:
340-
[a-zA-ZА-Яа-я_$@:\u0001-\u0009\u000b\u000c\u000e-\u001E\u00C0-\u00FF]
340+
[a-zA-ZА-Яа-я_$@:\u0001-\u0008\u000b\u000c\u000e-\u001E\u00C0-\u00FF]
341341
;
342342
343343
fragment

handlebars/src/test/java/com/github/jknack/handlebars/internal/HbsParserTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.antlr.v4.runtime.tree.ParseTree;
77
import org.junit.Test;
88

9+
import static org.junit.Assert.assertEquals;
10+
911
public class HbsParserTest {
1012

1113
private boolean printTokens = true;
@@ -118,6 +120,21 @@ public void setDelim() {
118120
parse("{{=+-+ +-+=}}+-+test+-+");
119121
}
120122

123+
@Test
124+
public void whiteSpaceHandledEqually() {
125+
String withSpace = "{{helper param1=\"1\" param2=2}}";
126+
ParseTree tree = parse(withSpace);
127+
128+
String withNewlines = "{{helper\nparam1=\"1\"\nparam2=2}}";
129+
assertEquals("Newlines should be treated the same as spaces", tree.getText(), parse(withNewlines).getText());
130+
131+
String withDosNewlines = "{{helper\r\nparam1=\"1\"\r\nparam2=2}}";
132+
assertEquals("DOS-style newlines should be treated the same as spaces", tree.getText(), parse(withDosNewlines).getText());
133+
134+
String alignedWithTabs = "{{helper\n\tparam1=\"1\"\n\tparam2=2}}";
135+
assertEquals("Tab-aligned variables should be treated the same as spaces", tree.getText(), parse(alignedWithTabs).getText());
136+
}
137+
121138
private ParseTree parse(final String input) {
122139
return parse(input, "{{", "}}");
123140
}

0 commit comments

Comments
 (0)