summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2010-02-26 17:00:42 +0000
committerJannis Leidel <jannis@leidel.info>2010-02-26 17:00:42 +0000
commit7c23a5303cb5b5d01e6fb25d30676a5e95db2ecc (patch)
treeda58e606be3501138d6ffa0b57cebb2ec53e67bc /django
parent079d9f37383d3b44bbfffcee56925d82b3d838a9 (diff)
[1.1.X] Fixed #5971 - Fixed inconsistent behaviour of the TokenParser when parsing filters that follow constant strings or variables. Thanks Dmitri Fedortchenko, Adam Vandenberg and Ramiro Morales.
Backport of r12471. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12610 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/template/__init__.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py
index d9668a1d4a..f405e46664 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -411,6 +411,20 @@ class TokenParser(object):
"A microparser that parses for a value: some string constant or variable name."
subject = self.subject
i = self.pointer
+
+ def next_space_index(subject, i):
+ "Increment pointer until a real space (i.e. a space not within quotes) is encountered"
+ while i < len(subject) and subject[i] not in (' ', '\t'):
+ if subject[i] in ('"', "'"):
+ c = subject[i]
+ i += 1
+ while i < len(subject) and subject[i] != c:
+ i += 1
+ if i >= len(subject):
+ raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject))
+ i += 1
+ return i
+
if i >= len(subject):
raise TemplateSyntaxError("Searching for value. Expected another value but found end of string: %s" % subject)
if subject[i] in ('"', "'"):
@@ -421,6 +435,10 @@ class TokenParser(object):
if i >= len(subject):
raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject))
i += 1
+
+ # Continue parsing until next "real" space, so that filters are also included
+ i = next_space_index(subject, i)
+
res = subject[p:i]
while i < len(subject) and subject[i] in (' ', '\t'):
i += 1
@@ -429,15 +447,7 @@ class TokenParser(object):
return res
else:
p = i
- while i < len(subject) and subject[i] not in (' ', '\t'):
- if subject[i] in ('"', "'"):
- c = subject[i]
- i += 1
- while i < len(subject) and subject[i] != c:
- i += 1
- if i >= len(subject):
- raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject))
- i += 1
+ i = next_space_index(subject, i)
s = subject[p:i]
while i < len(subject) and subject[i] in (' ', '\t'):
i += 1