Permalink
Browse files

Allow for escaped ] characters in [] IDs

Allows for ] literal characters to be used within [] IDs by prefixing them with the \ character. `\` literal at the end of the  may be referenced by the `\\` sequence if conflicting. Under most circumstances the `\\` sequence will continue to work.

Potentially breaking change for users of [] ids that have `\\` anywhere in the id or `\` at the end of the id.

Fixes #1092
1 parent 641fe33 commit 08781798f564a68abee11c74e2b98272657b2a56 @kpdecker kpdecker committed Sep 16, 2015
Showing with 12 additions and 1 deletion.
  1. +6 −0 spec/parser.js
  2. +5 −0 spec/tokenizer.js
  3. +1 −1 src/handlebars.l
View
@@ -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');
View
@@ -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']);
View
@@ -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';

0 comments on commit 0878179

Please sign in to comment.