1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

magic-removal: Fixed #1198 -- Modified handling of escape characters in filter arguments, and updated unit tests to reflect the change.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2713 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2006-04-18 13:41:21 +00:00
parent 6112223100
commit 4b3048d8a9
4 changed files with 61 additions and 42 deletions

View File

@ -519,9 +519,9 @@ class FilterExpression(object):
args = []
constant_arg, i18n_arg, var_arg = match.group("constant_arg", "i18n_arg", "var_arg")
if i18n_arg:
args.append((False, _(i18n_arg.replace('\\', ''))))
args.append((False, _(i18n_arg.replace(r'\"', '"'))))
elif constant_arg:
args.append((False, constant_arg.replace('\\', '')))
args.append((False, constant_arg.replace(r'\"', '"')))
elif var_arg:
args.append((True, var_arg))
filter_func = parser.find_filter(filter_name)

View File

@ -1,14 +1,16 @@
"""
r"""
>>> format(my_birthday, '')
''
>>> format(my_birthday, 'a')
'p.m.'
>>> format(my_birthday, 'A')
'PM'
>>> format(my_birthday, 'd')
'08'
>>> format(my_birthday, 'j')
'7'
'8'
>>> format(my_birthday, 'l')
'Saturday'
'Sunday'
>>> format(my_birthday, 'L')
'False'
>>> format(my_birthday, 'm')
@ -24,7 +26,7 @@
>>> format(my_birthday, 'P')
'10 p.m.'
>>> format(my_birthday, 'r')
'Sat, 7 Jul 1979 22:00:00 +0100'
'Sun, 8 Jul 1979 22:00:00 +0100'
>>> format(my_birthday, 's')
'00'
>>> format(my_birthday, 'S')
@ -34,9 +36,9 @@
>>> format(my_birthday, 'T')
'CET'
>>> format(my_birthday, 'U')
'300445200'
'300531600'
>>> format(my_birthday, 'w')
'6'
'0'
>>> format(my_birthday, 'W')
'27'
>>> format(my_birthday, 'y')
@ -44,7 +46,7 @@
>>> format(my_birthday, 'Y')
'1979'
>>> format(my_birthday, 'z')
'188'
'189'
>>> format(my_birthday, 'Z')
'3600'
@ -57,8 +59,11 @@
>>> format(wintertime, 'O')
'+0100'
>>> format(my_birthday, 'Y z \\C\\E\\T')
'1979 188 CET'
>>> format(my_birthday, r'Y z \C\E\T')
'1979 189 CET'
>>> format(my_birthday, r'jS o\f F')
'8th of July'
"""
from django.utils import dateformat, translation
@ -70,6 +75,6 @@ translation.activate('en-us')
time.tzset()
my_birthday = datetime.datetime(1979, 7, 7, 22, 00)
my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
summertime = datetime.datetime(2005, 10, 30, 1, 00)
wintertime = datetime.datetime(2005, 10, 30, 4, 00)

View File

@ -1,4 +1,4 @@
"""
r"""
>>> floatformat(7.7)
'7.7'
>>> floatformat(7.0)
@ -12,8 +12,8 @@
>>> floatformat(0.0)
'0'
>>> addslashes('"double quotes" and \\'single quotes\\'')
'\\\\"double quotes\\\\" and \\\\\\'single quotes\\\\\\''
>>> addslashes('"double quotes" and \'single quotes\'')
'\\"double quotes\\" and \\\'single quotes\\\''
>>> capfirst('hello world')
'Hello world'
@ -21,17 +21,17 @@
>>> fix_ampersands('Jack & Jill & Jeroboam')
'Jack & Jill & Jeroboam'
>>> linenumbers('line 1\\nline 2')
'1. line 1\\n2. line 2'
>>> linenumbers('line 1\nline 2')
'1. line 1\n2. line 2'
>>> linenumbers('\\n'.join(['x'] * 10))
'01. x\\n02. x\\n03. x\\n04. x\\n05. x\\n06. x\\n07. x\\n08. x\\n09. x\\n10. x'
>>> linenumbers('\n'.join(['x'] * 10))
'01. x\n02. x\n03. x\n04. x\n05. x\n06. x\n07. x\n08. x\n09. x\n10. x'
>>> lower('TEST')
'test'
>>> lower(u'\\xcb') # uppercase E umlaut
u'\\xeb'
>>> lower(u'\xcb') # uppercase E umlaut
u'\xeb'
>>> make_list('abc')
['a', 'b', 'c']
@ -48,7 +48,7 @@ u'\\xeb'
>>> stringformat(1, 'z')
''
>>> title('a nice title, isn\\'t it?')
>>> title('a nice title, isn\'t it?')
"A Nice Title, Isn't It?"
@ -68,8 +68,8 @@ u'\\xeb'
>>> upper('Mixed case input')
'MIXED CASE INPUT'
>>> upper(u'\\xeb') # lowercase e umlaut
u'\\xcb'
>>> upper(u'\xeb') # lowercase e umlaut
u'\xcb'
>>> urlencode('jack & jill')
@ -91,8 +91,8 @@ u'\\xcb'
>>> wordcount('lots of words')
3
>>> wordwrap('this is a long paragraph of text that really needs to be wrapped I\\'m afraid', 14)
"this is a long\\nparagraph of\\ntext that\\nreally needs\\nto be wrapped\\nI'm afraid"
>>> wordwrap('this is a long paragraph of text that really needs to be wrapped I\'m afraid', 14)
"this is a long\nparagraph of\ntext that\nreally needs\nto be wrapped\nI'm afraid"
>>> ljust('test', 10)
'test '
@ -124,7 +124,7 @@ u'\\xcb'
>>> linebreaks('line 1')
'<p>line 1</p>'
>>> linebreaks('line 1\\nline 2')
>>> linebreaks('line 1\nline 2')
'<p>line 1<br />line 2</p>'
>>> removetags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags', 'script img')
@ -133,19 +133,15 @@ u'\\xcb'
>>> striptags('some <b>html</b> with <script>alert("You smell")</script> disallowed <img /> tags')
'some html with alert("You smell") disallowed tags'
>>> dictsort([{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 63, 'name': 'Ra Ra Rasputin'},\
{'name': 'Jonny B Goode', 'age': 18}], 'age')
[{'age': 18, 'name': 'Jonny B Goode'},\
{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 63, 'name': 'Ra Ra Rasputin'}]
>>> dictsort([{'age': 23, 'name': 'Barbara-Ann'},
... {'age': 63, 'name': 'Ra Ra Rasputin'},
... {'name': 'Jonny B Goode', 'age': 18}], 'age')
[{'age': 18, 'name': 'Jonny B Goode'}, {'age': 23, 'name': 'Barbara-Ann'}, {'age': 63, 'name': 'Ra Ra Rasputin'}]
>>> dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 63, 'name': 'Ra Ra Rasputin'},\
{'name': 'Jonny B Goode', 'age': 18}], 'age')
[{'age': 63, 'name': 'Ra Ra Rasputin'},\
{'age': 23, 'name': 'Barbara-Ann'},\
{'age': 18, 'name': 'Jonny B Goode'}]
>>> dictsortreversed([{'age': 23, 'name': 'Barbara-Ann'},
... {'age': 63, 'name': 'Ra Ra Rasputin'},
... {'name': 'Jonny B Goode', 'age': 18}], 'age')
[{'age': 63, 'name': 'Ra Ra Rasputin'}, {'age': 23, 'name': 'Barbara-Ann'}, {'age': 18, 'name': 'Jonny B Goode'}]
>>> first([0,1,2])
0
@ -196,13 +192,13 @@ False
'aceg'
>>> unordered_list(['item 1', []])
'\\t<li>item 1</li>'
'\t<li>item 1</li>'
>>> unordered_list(['item 1', [['item 1.1', []]]])
'\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t</ul>\\n\\t</li>'
'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t</ul>\n\t</li>'
>>> unordered_list(['item 1', [['item 1.1', []], ['item 1.2', []]]])
'\\t<li>item 1\\n\\t<ul>\\n\\t\\t<li>item 1.1</li>\\n\\t\\t<li>item 1.2</li>\\n\\t</ul>\\n\\t</li>'
'\t<li>item 1\n\t<ul>\n\t\t<li>item 1.1</li>\n\t\t<li>item 1.2</li>\n\t</ul>\n\t</li>'
>>> add('1', '2')
3
@ -228,6 +224,8 @@ False
# real testing of date() is in dateformat.py
>>> date(datetime.datetime(2005, 12, 29), "d F Y")
'29 December 2005'
>>> date(datetime.datetime(2005, 12, 29), r'jS o\f F')
'29th of December'
# real testing of time() is done in dateformat.py
>>> time(datetime.time(13), "h")

View File

@ -4,6 +4,7 @@ from django.conf import settings
from django import template
from django.template import loader
from django.utils.translation import activate, deactivate, install
from datetime import datetime
import traceback
#################################
@ -152,6 +153,12 @@ TEMPLATE_TESTS = {
# the exception propogates
'basic-syntax34': (r'1{{ var.method4 }}2', {"var": SomeClass()}, SomeOtherException),
# Escaped backslash in argument
'basic-syntax35': (r'{{ var|default_if_none:"foo\bar" }}', {"var": None}, r'foo\bar'),
# Escaped backslash using known escape char
'basic-syntax35': (r'{{ var|default_if_none:"foo\now" }}', {"var": None}, r'foo\now'),
### COMMENT TAG ###########################################################
'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"),
'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"),
@ -433,6 +440,15 @@ TEMPLATE_TESTS = {
'widthratio08': ('{% widthratio %}', {}, template.TemplateSyntaxError),
'widthratio09': ('{% widthratio a b %}', {'a':50,'b':100}, template.TemplateSyntaxError),
'widthratio10': ('{% widthratio a b 100.0 %}', {'a':50,'b':100}, template.TemplateSyntaxError),
### NOW TAG ########################################################
# Simple case
'now01' : ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
# Check parsing of escaped and special characters
'now02' : ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError),
# 'now03' : ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)),
# 'now04' : ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year))
}
def test_template_loader(template_name, template_dirs=None):