Use `token.split_contents()` in tags that can take variables (fixes #6271 and #18260) #751

merged 1 commit into from Feb 23, 2013

3 participants

Django member

After fixing #19882, I grepped through the code to check for usage of token.contents.split().

It turned out that several other tags were affected by the same issue, so I fix those.

There are still tags that use token.contents.split() instead of token.split_contents(), but since they don't take any variable argument, they are not affected.

Here's a list of the remaining instances of token.contents.split() and the tags they are associated with:

django/template/ <not a template tag>
django/template/ autoescape
django/template/ filter
django/template/ load
django/template/ templatetag
django/template/ block
django/templatetags/ get_available_languages
django/templatetags/ get_current_language
django/templatetags/ get_current_language_bidi
django/templatetags/ get_static_prefix, get_media_prefix
django/templatetags/ get_current_timezone

Also note that there are still tags that are affected by this issue in contrib.
Namely, all the tags from contrib.comments as well as the get_admin_log for contrib.admin.
Those did not have any tests and I didn't see any bugs in the tracker, so I left them as-is (for now).

Django member

I've wanted to write that patch forever...

Django member

Would you mind:

  • adding a short comment above each use of .content.split that you didn't change?

    # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments

  • rebasing this to a single commit with the following commit message ?

    Used token.split_contents() for tokenisation in template tags accepting variables.

    Fixed #6271, #18260.

Then I'll run the tests and merge it.

Django member


As discussed on IRC, I'll file a separate ticket for the similar issues in contrib.comments and contrib.admin.

@aaugustin aaugustin merged commit 5278776 into django:master Feb 23, 2013

Here you parse_filter the fragment_name, but it's never resolved above. It only works because the FilterExpression.str method returns self.token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment