Skip to content

Commit

Permalink
Fixed #15092 -- Made {% now %} work with single-quoted string argum…
Browse files Browse the repository at this point in the history
…ents. Thanks to ninja_otoko for the report and to steveire, Aymeric Augustin and Claude Paroz for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jphalip committed Jan 24, 2012
1 parent 804bd40 commit 6ae393d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 3 additions & 3 deletions django/template/defaulttags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,10 +1049,10 @@ def now(parser, token):
It is {% now "jS F Y H:i" %}
"""
bits = token.contents.split('"')
if len(bits) != 3:
bits = token.split_contents()
if len(bits) != 2:
raise TemplateSyntaxError("'now' statement takes one argument")
format_string = bits[1]
format_string = bits[1][1:-1]
return NowNode(format_string)

@register.tag
Expand Down
18 changes: 11 additions & 7 deletions tests/regressiontests/templates/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,14 +1462,18 @@ def get_template_tests(self):

### 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))
'now01': ('{% now "j n Y" %}', {}, "%d %d %d" % (
datetime.now().day, datetime.now().month, datetime.now().year)),
# Check parsing of locale strings
'now05': ('{% now "DATE_FORMAT" %}', {}, date_format(datetime.now())),
'now02': ('{% now "DATE_FORMAT" %}', {}, date_format(datetime.now())),
# Also accept simple quotes - #15092
'now03': ("{% now 'j n Y' %}", {}, "%d %d %d" % (
datetime.now().day, datetime.now().month, datetime.now().year)),
'now04': ("{% now 'DATE_FORMAT' %}", {}, date_format(datetime.now())),
'now05': ('''{% now 'j "n" Y'%}''', {}, '''%d "%d" %d''' % (
datetime.now().day, datetime.now().month, datetime.now().year)),
'now06': ('''{% now "j 'n' Y"%}''', {}, '''%d '%d' %d''' % (
datetime.now().day, datetime.now().month, datetime.now().year)),

### URL TAG ########################################################
# Successes
Expand Down

0 comments on commit 6ae393d

Please sign in to comment.