id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux
12945 url tag breaks on spaces between delimiting commas since [12503] jklaiho nobody "The parsing of the arguments to the {% url %} tag was changed in [12503] to account for commas etc. appearing in literal strings, fixing #12072.
Unfortunately, the same changeset broke the use of spaces between the commas that delimit arguments, producing a !TemplateSyntaxError: Malformed arguments to url tag.
Admittedly, spaces in the url tag have never been ""officially sanctioned"", given that the documentation example for the url tag looks like this:
{{{
{% url path.to.some_view arg1,arg2,name1=value1 %}
}}}
But in a lot of real-world code (including all of our projects), it's common to use spaces between the commas, because it looks cleaner and is easier to read:
{{{
{% url path.to.some_view arg1, arg2, name1=value1 %}
}}}
I'd wager that the previously working form with spaces is common enough out in the wild for this change to bite a lot of people pretty hard. While the documentation example doesn't use spaces, it doesn't explicitly state that they are forbidden, either, and typing them comes naturally given the tendency to separate commas with spaces in Python code.
I tested and found that downgrading Django to r12502 allowed for spaces between commas again.
So, the possibilities:
1. Stick with the change, forcing everybody to remove any spaces they may have in their url tags, but document the change as backwards-incompatible. Given the non-specific error message, this will cause a lot of head-scratching, especially since looking at the deeply nested code in URLNode (and the hairy regex preceding it) doesn't make the problem immediately clear. This can be alleviated by documenting it as backwards-incompatible, of course.
2. Make the regex more permissive, allowing at least a single space after each comma.
IMHO option 2 would be the least painful way forward. I don't believe there's any convincing reason to be strict about this, given the downsides in the real world." closed Template system master fixed url tag pycamp2010 ramusus@… cwalker32@… alex@… aribao@… hvdklauw@… bronger@… Accepted 1 0 0 0