Skip to content

Commit

Permalink
fix escape filer #835
Browse files Browse the repository at this point in the history
  • Loading branch information
devoidfury committed Sep 7, 2016
1 parent a3de5e6 commit c13d81e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ var filters = {
},

escape: function(str) {
if(typeof str === 'string') {
return r.markSafe(lib.escape(str));
if(str instanceof r.SafeString) {
return str;
}
return str;
return r.markSafe(lib.escape(str.toString()));
},

safe: function(str) {
Expand Down
9 changes: 9 additions & 0 deletions tests/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@
finish(done);
});

it('should work with non-string values', function(done) {
var res1 = render('{{ foo | escape }}', {foo: ['<html>']}, { autoescape: false });
expect(res1).to.be('&lt;html&gt;');

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

it('should not escape safe strings with autoescape on', function(done) {
var res1 = render('{{ "<html>" | safe | escape }}', {}, { autoescape: true });
expect(res1).to.be('<html>');
Expand Down

0 comments on commit c13d81e

Please sign in to comment.