Skip to content

Commit

Permalink
Escape template names
Browse files Browse the repository at this point in the history
Since the compiler was not interpreting template names when emitting
javascript code with those as literals, and instead merely concatenating
string delimiters onto the end, template names ending in a backslash
or containing a newline or double quotes would cause a parser failure
when loading the compiled template.

This additionally escapes the null character, as some browsers will omit
it during parsing, making the template name not make a round-trip from
what was specified to what is cached.
  • Loading branch information
aredridel committed Feb 13, 2015
1 parent 56f90ed commit f7da460
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
};

return '(function(){dust.register(' +
(name ? '"' + name + '"' : 'null') + ',' +
(name ? '"' + dust.escapeJs(name) + '"' : 'null') + ',' +
compiler.compileNode(context, ast) +
');' +
compileBlocks(context) +
Expand Down
7 changes: 7 additions & 0 deletions test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ var coreTests = [
expected: "Hello World!",
message: "should test basic text rendering"
},
{
name: "confusing \" \n \' \u0000 \u2028 \u2029 template name\\",
source: "Hello World!",
context: {},
expected: "Hello World!",
message: "javascript-special characters in template names shouldn't break things"
},
{
name: "global_template",
source: '{#helper foo="bar" boo="boo"} {/helper}',
Expand Down

0 comments on commit f7da460

Please sign in to comment.