Skip to content

Commit

Permalink
Merge pull request #843 from atian25/escape-null
Browse files Browse the repository at this point in the history
fix: undefined escape at #836
  • Loading branch information
vecmezoni authored Sep 13, 2016
2 parents bee67d5 + dd51fb5 commit 7671d29
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ var filters = {
if(str instanceof r.SafeString) {
return str;
}
str = (str === null || str === undefined) ? '' : str;
return r.markSafe(lib.escape(str.toString()));
},

safe: function(str) {
str = (str === null || str === undefined) ? '' : str;
return r.markSafe(str);
},

Expand Down
12 changes: 12 additions & 0 deletions tests/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,10 +1309,22 @@
expect(res).to.be('&><\'"');
});

render('{{ foo }}', { foo: null }, { autoescape: true }, function (err, res) {
expect(res).to.be('');
});

render('{{ foo | safe }}', { foo: null }, { autoescape: true }, function (err, res) {
expect(res).to.be('');
});

render('{{ foo }}', { foo: ['<p>foo</p>']}, { autoescape: true }, function(err, res) {
expect(res).to.be('&lt;p&gt;foo&lt;/p&gt;');
});

render('{{ foo | safe }}', { foo: '<p>foo</p>' }, { autoescape: true }, function (err, res) {
expect(res).to.be('<p>foo</p>');
});

render('{{ foo }}', { foo: {toString: function() {return '<p>foo</p>'}}}, { autoescape: true }, function(err, res) {
expect(res).to.be('&lt;p&gt;foo&lt;/p&gt;');
});
Expand Down
4 changes: 4 additions & 0 deletions tests/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@

var res2 = render('{{ foo | escape }}', {foo: {toString: function() { return '<html>'; }}}, { autoescape: false });
expect(res2).to.be('&lt;html&gt;');

var res3 = render('{{ foo | escape }}', { foo: null }, { autoescape: false });
expect(res3).to.be('');

finish(done);
});

Expand Down

0 comments on commit 7671d29

Please sign in to comment.