mirror of
https://github.com/django/django.git
synced 2025-08-01 09:32:50 +00:00
Added consistent support for double- and single-quote delimiters in templates.
Some template filters and tags understood single-quoted arguments, others didn't. This makes everything consistent. Based on a patch from akaihola. Fixed #7295. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10118 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f5c07f89e3
commit
a6f429e37e
5 changed files with 152 additions and 66 deletions
59
tests/regressiontests/templates/parser.py
Normal file
59
tests/regressiontests/templates/parser.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
"""
|
||||
Testing some internals of the template processing. These are *not* examples to be copied in user code.
|
||||
"""
|
||||
|
||||
filter_parsing = r"""
|
||||
>>> from django.template import FilterExpression, Parser
|
||||
|
||||
>>> c = {'article': {'section': u'News'}}
|
||||
>>> p = Parser("")
|
||||
>>> def fe_test(s): return FilterExpression(s, p).resolve(c)
|
||||
|
||||
>>> fe_test('article.section')
|
||||
u'News'
|
||||
>>> fe_test('article.section|upper')
|
||||
u'NEWS'
|
||||
>>> fe_test(u'"News"')
|
||||
u'News'
|
||||
>>> fe_test(u"'News'")
|
||||
u'News'
|
||||
>>> fe_test(ur'"Some \"Good\" News"')
|
||||
u'Some "Good" News'
|
||||
>>> fe_test(ur"'Some \'Bad\' News'")
|
||||
u"Some 'Bad' News"
|
||||
|
||||
>>> fe = FilterExpression(ur'"Some \"Good\" News"', p)
|
||||
>>> fe.filters
|
||||
[]
|
||||
>>> fe.var
|
||||
u'Some "Good" News'
|
||||
"""
|
||||
|
||||
variable_parsing = r"""
|
||||
>>> from django.template import Variable
|
||||
|
||||
>>> c = {'article': {'section': u'News'}}
|
||||
>>> Variable('article.section').resolve(c)
|
||||
u'News'
|
||||
>>> Variable(u'"News"').resolve(c)
|
||||
u'News'
|
||||
>>> Variable(u"'News'").resolve(c)
|
||||
u'News'
|
||||
|
||||
Translated strings are handled correctly.
|
||||
|
||||
>>> Variable('_(article.section)').resolve(c)
|
||||
u'News'
|
||||
>>> Variable('_("Good News")').resolve(c)
|
||||
u'Good News'
|
||||
>>> Variable("_('Better News')").resolve(c)
|
||||
u'Better News'
|
||||
|
||||
Escaped quotes work correctly as well.
|
||||
|
||||
>>> Variable(ur'"Some \"Good\" News"').resolve(c)
|
||||
u'Some "Good" News'
|
||||
>>> Variable(ur"'Some \'Better\' News'").resolve(c)
|
||||
u"Some 'Better' News"
|
||||
|
||||
"""
|
Loading…
Add table
Add a link
Reference in a new issue