-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Fixed #34578 -- Made "join" template filter respect autoescape for joiner. #16873
Conversation
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.
Hello! Thank you for your contribution 💪
As it's your first contribution be sure to check out the patch review checklist.
If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!
If you have any design or process questions then you can ask in the Django forum.
Welcome aboard ⛵️!
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.
@rajeeshrp Thanks 👍 I left comments.
@rajeeshrp Thanks 👍 Welcome aboard ⛵ I pushed small edits and squashed commits. |
I was going to make a small suggestion unrelated to the ticket in the function but I'll wait until you've merged it and submit a PR separately 🤔 |
Please share 👀 |
Oh hm after your edit it doesn't really refactor that well but going on the previous version (and this was a thing in the original code so no criticism of rajeeshp here): @register.filter(is_safe=True, needs_autoescape=True)
def join(value, arg, autoescape=True):
"""Join a list with a string, like Python's ``str.join(list)``."""
try:
if autoescape:
data = conditional_escape(arg).join(conditional_escape(v) for v in value)
else:
data = arg.join(value)
except TypeError: # Fail silently if arg isn't iterable.
return value
return mark_safe(data) The point is to use a generator expression instead of a material list:
You could also "improve" if further with the |
A list comprehension is preferable here as |
Agreed 👍 |
Well TIL! ❤️ |
autoescape
isoff
,join
filter will not escape the joining string now.