Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #732 from naltatis/master

fixing string interpolation escaping
  • Loading branch information...
commit eea866842da42a82182a73e316c06078dfbddd4d 2 parents 7c0c801 + b1e8c58
@tj tj authored
View
10 lib/lexer.js
@@ -4,6 +4,8 @@
* Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
+var utils = require('./utils');
+
/**
* Initialize `Lexer` with the given `str`.
@@ -502,12 +504,6 @@ Lexer.prototype = {
return states[states.length - 1];
}
- function interpolate(attr) {
- return attr.replace(/#\{([^}]+)\}/g, function(_, expr){
- return quote + " + (" + expr + ") + " + quote;
- });
- }
-
this.consume(index + 1);
tok.attrs = {};
tok.escaped = {};
@@ -535,7 +531,7 @@ Lexer.prototype = {
tok.escaped[key] = escapedAttr;
tok.attrs[key] = '' == val
? true
- : interpolate(val);
+ : utils.interpolate(val);
key = val = '';
}
break;
View
2  lib/utils.js
@@ -16,7 +16,7 @@
var interpolate = exports.interpolate = function(str){
return str.replace(/(\\)?([#!]){(.*?)}/g, function(str, escape, flag, code){
return escape
- ? str
+ ? flag + "{" + code + "}"
: "' + "
+ ('!' == flag ? '' : 'escape')
+ "((interp = " + code.replace(/\\'/g, "'")
View
2  test/cases/attrs.interpolation.html
@@ -1 +1 @@
-<a href="/user/5"></a>
+<a href="/user/5" title="foo #{id}"></a>
View
2  test/cases/attrs.interpolation.jade
@@ -1,2 +1,2 @@
- var id = 5
-a(href='/user/#{id}')
+a(href='/user/#{id}', title="foo \#{id}")
View
2  test/cases/text.interpolation.html
@@ -0,0 +1,2 @@
+<p>foo bar</p>
+<p>foo #{foo}</p>
View
3  test/cases/text.interpolation.jade
@@ -0,0 +1,3 @@
+foo = "bar"
+p foo #{foo}
+p foo \#{foo}
Please sign in to comment.
Something went wrong with that request. Please try again.