summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-09-16 16:11:56 -0500
committerkpdecker <kpdecker@gmail.com>2015-09-16 16:15:01 -0500
commit08781798f564a68abee11c74e2b98272657b2a56 (patch)
tree0f725f743bb28cbc7ada747132edab483c9c5649
parent641fe335df78c436aecf5e7173fde529f72ac2f8 (diff)
downloadhandlebars.js-08781798f564a68abee11c74e2b98272657b2a56.zip
handlebars.js-08781798f564a68abee11c74e2b98272657b2a56.tar.gz
handlebars.js-08781798f564a68abee11c74e2b98272657b2a56.tar.bz2
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
-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';