Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to issue #700; should eliminate double-escaping problem. #701

Merged
merged 1 commit into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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