Skip to content

Commit

Permalink
Merge pull request #701 from legutierr/master
Browse files Browse the repository at this point in the history
Fix to issue #700; should eliminate double-escaping problem.
  • Loading branch information
carljm committed Mar 17, 2016
1 parent 5b0a0bd commit c49efe3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var filters = {

escape: function(str) {
if(typeof str === 'string') {
return lib.escape(str);
return r.markSafe(lib.escape(str));
}
return str;
},
Expand Down
27 changes: 27 additions & 0 deletions tests/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@
finish(done);
});

it('should not double escape strings', function(done) {
var res = render('{{ "<html>" | escape | escape }}', {}, { autoescape: false });
expect(res).to.be('&lt;html&gt;');
finish(done);
});

it('should not double escape with autoescape on', function(done) {
var res = render('{% set val = "<html>" | escape %}{{ val }}', {}, { autoescape: true });
expect(res).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>');

var res2 = render('{% set val = "<html>" | safe | e %}{{ val }}', {}, { autoescape: true });
expect(res2).to.be('<html>');
finish(done);
});

it('should keep strings escaped after they have been escaped', function(done) {
var res = render('{% set val = "<html>" | e | safe %}{{ val }}', {}, { autoescape: false });
expect(res).to.be('&lt;html&gt;');
finish(done);
});

it('dictsort', function(done) {
// no real foolproof way to test that a js obj has been transformed
// from unsorted -> sorted, as its enumeration ordering is undefined
Expand Down

0 comments on commit c49efe3

Please sign in to comment.