summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2010-02-23 05:17:39 +0000
committerJustin Bronn <jbronn@gmail.com>2010-02-23 05:17:39 +0000
commit349827996b5bcf29886bd1e57bc07147d840229e (patch)
tree78895196c463f7d194ef139d262b6c3b8e15b157 /django
parent6ed7bd5609d298858c02d5d3b6357b434df06d9f (diff)
Fixed #12072 -- Certain characters no longer break url tag. Thanks, Alexander Dutton.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12503 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/template/defaulttags.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 124841c614..0db77f17af 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -1071,6 +1071,13 @@ def templatetag(parser, token):
return TemplateTagNode(tag)
templatetag = register.tag(templatetag)
+# Regex for URL arguments including filters
+url_arg_re = re.compile(
+ r"(?:(%(name)s)=)?(%(value)s(?:\|%(name)s(?::%(value)s)?)*)" % {
+ 'name':'\w+',
+ 'value':'''(?:(?:'[^']*')|(?:"[^"]*")|(?:[\w\.-]+))'''},
+ re.VERBOSE)
+
def url(parser, token):
"""
Returns an absolute URL matching given view with its parameters.
@@ -1118,13 +1125,20 @@ def url(parser, token):
asvar = bits.next()
break
else:
- for arg in bit.split(","):
- if '=' in arg:
- k, v = arg.split('=', 1)
- k = k.strip()
- kwargs[k] = parser.compile_filter(v)
- elif arg:
- args.append(parser.compile_filter(arg))
+ end = 0
+ for i, match in enumerate(url_arg_re.finditer(bit)):
+ if (i == 0 and match.start() != 0) or \
+ (i > 0 and (bit[end:match.start()] != ',')):
+ raise TemplateSyntaxError("Malformed arguments to url tag")
+ end = match.end()
+ name, value = match.group(1), match.group(2)
+ if name:
+ kwargs[name] = parser.compile_filter(value)
+ else:
+ args.append(parser.compile_filter(value))
+ if end != len(bit):
+ raise TemplateSyntaxError("Malformed arguments to url tag")
+
return URLNode(viewname, args, kwargs, asvar)
url = register.tag(url)