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: undefined escape at #836 #843

Merged
merged 1 commit into from
Sep 13, 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: 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please fix normalize function and remove false from there and use normalize here.
I don't see any idea behind it

Copy link
Contributor Author

@atian25 atian25 Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe another PR. This one is focus at quick bug fix.
I'm afraid it(change normalize) will cause BREAK CHANGE.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll merge it to 2.x, please prepare pull request for master

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you rebase this branch on 2.x?

Copy link
Contributor Author

@atian25 atian25 Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, hold on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vecmezoni plz review again. The ci is fail, but local test is ok, could you trigger it again?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't trigger CI, you can change commit hash and push it with force. It would trigger Appveyour

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vecmezoni done, travis is pass.

return r.markSafe(lib.escape(str.toString()));
},

safe: function(str) {
str = (str === null || str === undefined) ? '' : str;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('');
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add render('{{ foo | safe }}', { foo: '<html>' }, { autoescape: true } test for safe filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


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