diff --git a/django/template/__init__.py b/django/template/__init__.py
|
a
|
b
|
|
| 409 | 409 | "A microparser that parses for a value: some string constant or variable name." |
| 410 | 410 | subject = self.subject |
| 411 | 411 | i = self.pointer |
| | 412 | |
| | 413 | def __next_space_index(subject, i): |
| | 414 | """Increment pointer until a real space (i.e. a space not within quotes) is encountered""" |
| | 415 | while i < len(subject) and subject[i] not in (' ', '\t'): |
| | 416 | if subject[i] in ('"', "'"): |
| | 417 | c = subject[i] |
| | 418 | i += 1 |
| | 419 | while i < len(subject) and subject[i] != c: |
| | 420 | i += 1 |
| | 421 | if i >= len(subject): |
| | 422 | raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject)) |
| | 423 | i += 1 |
| | 424 | return i |
| | 425 | |
| 412 | 426 | if i >= len(subject): |
| 413 | 427 | raise TemplateSyntaxError("Searching for value. Expected another value but found end of string: %s" % subject) |
| 414 | 428 | if subject[i] in ('"', "'"): |
| … |
… |
|
| 419 | 433 | if i >= len(subject): |
| 420 | 434 | raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject)) |
| 421 | 435 | i += 1 |
| | 436 | |
| | 437 | # Continue parsing until next "real" space, so that filters are also included |
| | 438 | i = __next_space_index(subject, i) |
| | 439 | |
| 422 | 440 | res = subject[p:i] |
| 423 | 441 | while i < len(subject) and subject[i] in (' ', '\t'): |
| 424 | 442 | i += 1 |
| … |
… |
|
| 427 | 445 | return res |
| 428 | 446 | else: |
| 429 | 447 | p = i |
| 430 | | while i < len(subject) and subject[i] not in (' ', '\t'): |
| 431 | | if subject[i] in ('"', "'"): |
| 432 | | c = subject[i] |
| 433 | | i += 1 |
| 434 | | while i < len(subject) and subject[i] != c: |
| 435 | | i += 1 |
| 436 | | if i >= len(subject): |
| 437 | | raise TemplateSyntaxError("Searching for value. Unexpected end of string in column %d: %s" % (i, subject)) |
| 438 | | i += 1 |
| | 448 | i = __next_space_index(subject, i) |
| 439 | 449 | s = subject[p:i] |
| 440 | 450 | while i < len(subject) and subject[i] in (' ', '\t'): |
| 441 | 451 | i += 1 |
diff --git a/tests/regressiontests/tokenparser/__init__.py b/tests/regressiontests/tokenparser/__init__.py
new file mode 100644
diff --git a/tests/regressiontests/tokenparser/models.py b/tests/regressiontests/tokenparser/models.py
new file mode 100644
diff --git a/tests/regressiontests/tokenparser/tests.py b/tests/regressiontests/tokenparser/tests.py
new file mode 100644
|
-
|
+
|
|
| | 1 | """ |
| | 2 | Tests for TokenParser behavior in the face of quoted strings with spaces. |
| | 3 | |
| | 4 | >>> from django.template import TokenParser |
| | 5 | |
| | 6 | |
| | 7 | Test case 1: {% tag thevar|filter sometag %} |
| | 8 | |
| | 9 | >>> p = TokenParser("tag thevar|filter sometag") |
| | 10 | >>> p.tagname |
| | 11 | 'tag' |
| | 12 | |
| | 13 | >>> p.value() |
| | 14 | 'thevar|filter' |
| | 15 | |
| | 16 | >>> p.more() |
| | 17 | True |
| | 18 | |
| | 19 | >>> p.tag() |
| | 20 | 'sometag' |
| | 21 | |
| | 22 | >>> p.more() |
| | 23 | False |
| | 24 | |
| | 25 | |
| | 26 | Test case 2: {% tag "a value"|filter sometag %} |
| | 27 | |
| | 28 | >>> p = TokenParser('tag "a value"|filter sometag') |
| | 29 | >>> p.tagname |
| | 30 | 'tag' |
| | 31 | |
| | 32 | >>> p.value() |
| | 33 | '"a value"|filter' |
| | 34 | |
| | 35 | >>> p.more() |
| | 36 | True |
| | 37 | |
| | 38 | >>> p.tag() |
| | 39 | 'sometag' |
| | 40 | |
| | 41 | |
| | 42 | >>> p.more() |
| | 43 | False |
| | 44 | """ |