-
Notifications
You must be signed in to change notification settings - Fork 641
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
Conversation
@@ -119,6 +119,7 @@ var filters = { | |||
if(str instanceof r.SafeString) { | |||
return str; | |||
} | |||
if (str == null) str = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this, please use https://github.com/atian25/nunjucks/blob/d75a9993c79fb513e9e651bc938f5555213cb2a7/src/filters.js#L6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(value === null || value === undefined || value === false) {
render('{{ foo }}', { foo: false })
should render false
or empty string
?
@atian25 should fix |
@@ -1395,6 +1395,10 @@ | |||
expect(res).to.be('&><\'"'); | |||
}); | |||
|
|||
render('{{ foo }}', { foo: null }, { autoescape: true }, function (err, res) { | |||
expect(res).to.be(''); | |||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@vecmezoni updated. question:
|
boolean value should follow |
@fengmk2 agree. updated. |
@@ -119,10 +119,12 @@ var filters = { | |||
if(str instanceof r.SafeString) { | |||
return str; | |||
} | |||
str = (str === null || str === undefined) ? '' : str; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, hold on
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Merged. Waiting for |
2.5.1 released, cherry-picked this patch to master. |
return r.markSafe(lib.escape(str.toString())); | ||
}, | ||
|
||
safe: function(str) { | ||
str = (str === null || str === undefined) ? '' : str; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relate #843
https://github.com/mozilla/nunjucks/pull/836/files#r78286483