summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2013-05-29 15:30:43 -0400
committerkpdecker <kpdecker@gmail.com>2013-05-29 15:30:50 -0400
commit58a0b4f17d5338793c92cf4d104e9c44cc485c5b (patch)
tree4516d889eacbe948283c0e1dc603d2a72981daa1 /src
parent61f64e9f04ec6039759519371aff76cd504ed5da (diff)
downloadhandlebars.js-58a0b4f17d5338793c92cf4d104e9c44cc485c5b.zip
handlebars.js-58a0b4f17d5338793c92cf4d104e9c44cc485c5b.tar.gz
handlebars.js-58a0b4f17d5338793c92cf4d104e9c44cc485c5b.tar.bz2
Require matching braces in escaped expressions
Fixes #437
Diffstat (limited to 'src')
-rw-r--r--src/handlebars.l4
-rw-r--r--src/handlebars.yy7
2 files changed, 7 insertions, 4 deletions
diff --git a/src/handlebars.l b/src/handlebars.l
index 2afd715..aa76eab 100644
--- a/src/handlebars.l
+++ b/src/handlebars.l
@@ -26,7 +26,7 @@
<mu>"{{^" { return 'OPEN_INVERSE'; }
<mu>"{{"\s*"else" { return 'OPEN_INVERSE'; }
<mu>"{{{" { return 'OPEN_UNESCAPED'; }
-<mu>"{{&" { return 'OPEN_UNESCAPED'; }
+<mu>"{{&" { return 'OPEN'; }
<mu>"{{!--" { this.popState(); this.begin('com'); }
<mu>"{{!"[\s\S]*?"}}" { yytext = yytext.substr(3,yyleng-5); this.popState(); return 'COMMENT'; }
<mu>"{{" { return 'OPEN'; }
@@ -36,7 +36,7 @@
<mu>".." { return 'ID'; }
<mu>[\/.] { return 'SEP'; }
<mu>\s+ { /*ignore whitespace*/ }
-<mu>"}}}" { this.popState(); return 'CLOSE'; }
+<mu>"}}}" { this.popState(); return 'CLOSE_UNESCAPED'; }
<mu>"}}" { this.popState(); return 'CLOSE'; }
<mu>'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }
<mu>"'"("\\"[']|[^'])*"'" { yytext = yytext.substr(1,yyleng-2).replace(/\\'/g,"'"); return 'STRING'; }
diff --git a/src/handlebars.yy b/src/handlebars.yy
index e521c2e..56b3b70 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -42,8 +42,11 @@ closeBlock
;
mustache
- : OPEN inMustache CLOSE { $$ = new yy.MustacheNode($2[0], $2[1]); }
- | OPEN_UNESCAPED inMustache CLOSE { $$ = new yy.MustacheNode($2[0], $2[1], true); }
+ : OPEN inMustache CLOSE {
+ // Parsing out the '&' escape token at this level saves ~500 bytes after min due to the removal of one parser node.
+ $$ = new yy.MustacheNode($2[0], $2[1], $1[2] === '&');
+ }
+ | OPEN_UNESCAPED inMustache CLOSE_UNESCAPED { $$ = new yy.MustacheNode($2[0], $2[1], true); }
;