mirror of https://github.com/django/django.git
Fixed #5270 -- Allow template tags and filters to accept an emtpy string, patch from jdunck.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8393 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0ca738363a
commit
6d863fef8a
|
@ -485,9 +485,14 @@ class FilterExpression(object):
|
||||||
(token[:upto], token[upto:start], token[start:]))
|
(token[:upto], token[upto:start], token[start:]))
|
||||||
if var == None:
|
if var == None:
|
||||||
var, constant, i18n_constant = match.group("var", "constant", "i18n_constant")
|
var, constant, i18n_constant = match.group("var", "constant", "i18n_constant")
|
||||||
if i18n_constant:
|
if i18n_constant is not None:
|
||||||
var = '"%s"' % _(i18n_constant.replace(r'\"', '"'))
|
# Don't pass the empty string to gettext, because the empty
|
||||||
elif constant:
|
# string translates to meta information.
|
||||||
|
if i18n_constant == "":
|
||||||
|
var = '""'
|
||||||
|
else:
|
||||||
|
var = '"%s"' % _(i18n_constant.replace(r'\"', '"'))
|
||||||
|
elif constant is not None:
|
||||||
var = '"%s"' % constant.replace(r'\"', '"')
|
var = '"%s"' % constant.replace(r'\"', '"')
|
||||||
upto = match.end()
|
upto = match.end()
|
||||||
if var == None:
|
if var == None:
|
||||||
|
|
|
@ -365,6 +365,9 @@ class Templates(unittest.TestCase):
|
||||||
|
|
||||||
# Numbers as filter arguments should work
|
# Numbers as filter arguments should work
|
||||||
'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."),
|
'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."),
|
||||||
|
|
||||||
|
#filters should accept empty string constants
|
||||||
|
'filter-syntax20': ('{{ ""|default_if_none:"was none" }}', {}, ""),
|
||||||
|
|
||||||
### COMMENT SYNTAX ########################################################
|
### COMMENT SYNTAX ########################################################
|
||||||
'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),
|
'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),
|
||||||
|
@ -770,11 +773,12 @@ class Templates(unittest.TestCase):
|
||||||
'i18n14': ('{% cycle "foo" _("Password") _(\'Password\') as c %} {% cycle c %} {% cycle c %}', {'LANGUAGE_CODE': 'de'}, 'foo Passwort Passwort'),
|
'i18n14': ('{% cycle "foo" _("Password") _(\'Password\') as c %} {% cycle c %} {% cycle c %}', {'LANGUAGE_CODE': 'de'}, 'foo Passwort Passwort'),
|
||||||
'i18n15': ('{{ absent|default:_("Password") }}', {'LANGUAGE_CODE': 'de', 'absent': ""}, 'Passwort'),
|
'i18n15': ('{{ absent|default:_("Password") }}', {'LANGUAGE_CODE': 'de', 'absent': ""}, 'Passwort'),
|
||||||
'i18n16': ('{{ _("<") }}', {'LANGUAGE_CODE': 'de'}, '<'),
|
'i18n16': ('{{ _("<") }}', {'LANGUAGE_CODE': 'de'}, '<'),
|
||||||
|
'i18n17': ('{{ _("") }}', {'LANGUAGE_CODE': 'de'}, ''),
|
||||||
|
|
||||||
# Escaping inside blocktrans works as if it was directly in the
|
# Escaping inside blocktrans works as if it was directly in the
|
||||||
# template.
|
# template.
|
||||||
'i18n17': ('{% load i18n %}{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α & β'),
|
'i18n18': ('{% load i18n %}{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α & β'),
|
||||||
'i18n18': ('{% load i18n %}{% blocktrans with anton|force_escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α & β'),
|
'i18n19': ('{% load i18n %}{% blocktrans with anton|force_escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α & β'),
|
||||||
|
|
||||||
### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
|
### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue