summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/parser.js6
-rw-r--r--spec/tokenizer.js5
-rw-r--r--src/handlebars.l2
3 files changed, 12 insertions, 1 deletions
diff --git a/spec/parser.js b/spec/parser.js
index 3b7e3e4..4527d19 100644
--- a/spec/parser.js
+++ b/spec/parser.js
@@ -39,6 +39,12 @@ describe('parser', function() {
it('parses mustaches with - in a path', function() {
equals(astFor('{{foo-bar}}'), '{{ PATH:foo-bar [] }}\n');
});
+ it('parses mustaches with escaped [] in a path', function() {
+ equals(astFor('{{[foo[\\]]}}'), '{{ PATH:foo[] [] }}\n');
+ });
+ it('parses escaped \\\\ in path', function() {
+ equals(astFor('{{[foo\\\\]}}'), '{{ PATH:foo\\ [] }}\n');
+ });
it('parses mustaches with parameters', function() {
equals(astFor('{{foo bar}}'), '{{ PATH:foo [PATH:bar] }}\n');
diff --git a/spec/tokenizer.js b/spec/tokenizer.js
index dc077ce..428804e 100644
--- a/spec/tokenizer.js
+++ b/spec/tokenizer.js
@@ -146,6 +146,11 @@ describe('Tokenizer', function() {
shouldMatchTokens(result, ['OPEN', 'ID', 'SEP', 'ID', 'CLOSE', 'OPEN', 'ID', 'SEP', 'ID', 'CLOSE']);
});
+ it('allows escaped literals in []', function() {
+ var result = tokenize('{{foo.[bar\\]]}}');
+ shouldMatchTokens(result, ['OPEN', 'ID', 'SEP', 'ID', 'CLOSE']);
+ });
+
it('tokenizes {{.}} as OPEN ID CLOSE', function() {
var result = tokenize('{{.}}');
shouldMatchTokens(result, ['OPEN', 'ID', 'CLOSE']);
diff --git a/src/handlebars.l b/src/handlebars.l
index 4c3c304..e9de102 100644
--- a/src/handlebars.l
+++ b/src/handlebars.l
@@ -120,7 +120,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
<mu>{ID} return 'ID';
-<mu>'['[^\]]*']' return 'ID';
+<mu>'['('\\]'|[^\]])*']' yytext = yytext.replace(/\\([\\\]])/g,'$1'); return 'ID';
<mu>. return 'INVALID';
<INITIAL,mu><<EOF>> return 'EOF';