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

Merged
merged 1 commit into from Feb 23, 2013

3 participants

@bmispelon
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/base.py:262: <not a template tag>
django/template/defaulttags.py:492: autoescape
django/template/defaulttags.py:636: filter
django/template/defaulttags.py:1014: load
django/template/defaulttags.py:1186: templatetag
django/template/loader_tags.py:178: block
django/templatetags/i18n.py:188: get_available_languages
django/templatetags/i18n.py:260: get_current_language
django/templatetags/i18n.py:278: get_current_language_bidi
django/templatetags/static.py:30: get_static_prefix, get_media_prefix
django/templatetags/tz.py:193: 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).

@aaugustin
Django member

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

@aaugustin
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.

@bmispelon
Django member

Done.

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
@funkybob

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