Skip to content

Commit

Permalink
fix double-escaping of interpolated js slashes. Closes #784
Browse files Browse the repository at this point in the history
lame fix since we dont actually tokenize
text nodes
  • Loading branch information
tj committed Oct 9, 2012
1 parent 06c9210 commit 30c173d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/compiler.js
Expand Up @@ -435,8 +435,9 @@ Compiler.prototype = {
*/

visitText: function(text){
text = utils.text(text.val.replace(/\\/g, '\\\\'));
text = utils.text(text.val.replace(/\\/g, '_SLASH_'));
if (this.escape) text = escape(text);
text = text.replace(/_SLASH_/g, '\\\\');
this.buffer(text);
},

Expand Down
10 changes: 7 additions & 3 deletions lib/utils.js
Expand Up @@ -14,12 +14,16 @@
*/

var interpolate = exports.interpolate = function(str){
return str.replace(/(\\)?([#!]){(.*?)}/g, function(str, escape, flag, code){
return str.replace(/(_SLASH_)?([#!]){(.*?)}/g, function(str, escape, flag, code){
code = code
.replace(/\\'/g, "'")
.replace(/_SLASH_/g, '\\');

return escape
? str.slice(1)
? str.slice(7)
: "' + "
+ ('!' == flag ? '' : 'escape')
+ "((interp = " + code.replace(/\\'/g, "'")
+ "((interp = " + code
+ ") == null ? '' : interp) + '";
});
};
Expand Down

0 comments on commit 30c173d

Please sign in to comment.