Permalink
Browse files

add escaping of " quotes

  • Loading branch information...
1 parent 237a1fd commit 9320b2ea5df4dcf3d4593804bde31b4b175e563a @tj tj committed Sep 4, 2012
Showing with 6 additions and 2 deletions.
  1. +1 −1 lib/minstache.js
  2. +5 −1 test/index.js
View
@@ -42,7 +42,7 @@ function compile(str) {
for (var i = 0; i < toks.length; ++i) {
tok = toks[i];
if (i % 2 == 0) {
- js.push('"' + tok + '"');
+ js.push('"' + tok.replace(/"/g, '\\"') + '"');
} else {
if (!tok.match(/^[\w.]+$/)) throw new Error('invalid property "' + tok + '"');
js.push(' + escape(obj.' + tok + ') + ');
View
@@ -21,11 +21,15 @@ describe('{{id}}', function(){
mm('hi {{name.first}} {{name.last}}.', user).should.equal('hi tobi ferret.');
})
- it.only('should escape newlines', function(){
+ it('should escape newlines', function(){
var user = { name: 'tobi' };
mm('hi,\nhow are you {{name}}?', user).should.equal('hi,\nhow are you tobi?');
})
+ it('should escape quotes', function(){
+ mm('"hey"').should.equal('"hey"');
+ })
+
it('should only match words', function(done){
try {
mm('hi {{name)}}.');

0 comments on commit 9320b2e

Please sign in to comment.