Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5270 -- Allow template tags and filters to accept an emtpy str…

…ing, patch from jdunck.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8393 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d863fef8a992ef28b081e9fa6043e4a9799e965 1 parent 0ca7383
Gary Wilson Jr. authored
11  django/template/__init__.py
@@ -485,9 +485,14 @@ def __init__(self, token, parser):
485 485
                                            (token[:upto], token[upto:start], token[start:]))
486 486
             if var == None:
487 487
                 var, constant, i18n_constant = match.group("var", "constant", "i18n_constant")
488  
-                if i18n_constant:
489  
-                    var = '"%s"' %  _(i18n_constant.replace(r'\"', '"'))
490  
-                elif constant:
  488
+                if i18n_constant is not None:
  489
+                    # Don't pass the empty string to gettext, because the empty
  490
+                    # string translates to meta information.
  491
+                    if i18n_constant == "":
  492
+                        var = '""'
  493
+                    else:
  494
+                        var = '"%s"' %  _(i18n_constant.replace(r'\"', '"'))
  495
+                elif constant is not None:
491 496
                     var = '"%s"' % constant.replace(r'\"', '"')
492 497
                 upto = match.end()
493 498
                 if var == None:
8  tests/regressiontests/templates/tests.py
@@ -365,6 +365,9 @@ def get_template_tests(self):
365 365
 
366 366
             # Numbers as filter arguments should work
367 367
             'filter-syntax19': ('{{ var|truncatewords:1 }}', {"var": "hello world"}, "hello ..."),
  368
+            
  369
+            #filters should accept empty string constants
  370
+            'filter-syntax20': ('{{ ""|default_if_none:"was none" }}', {}, ""),
368 371
 
369 372
             ### COMMENT SYNTAX ########################################################
370 373
             'comment-syntax01': ("{# this is hidden #}hello", {}, "hello"),
@@ -770,11 +773,12 @@ def get_template_tests(self):
770 773
             'i18n14': ('{% cycle "foo" _("Password") _(\'Password\') as c %} {% cycle c %} {% cycle c %}', {'LANGUAGE_CODE': 'de'}, 'foo Passwort Passwort'),
771 774
             'i18n15': ('{{ absent|default:_("Password") }}', {'LANGUAGE_CODE': 'de', 'absent': ""}, 'Passwort'),
772 775
             'i18n16': ('{{ _("<") }}', {'LANGUAGE_CODE': 'de'}, '<'),
  776
+            'i18n17': ('{{ _("") }}', {'LANGUAGE_CODE': 'de'}, ''),
773 777
 
774 778
             # Escaping inside blocktrans works as if it was directly in the
775 779
             # template.
776  
-            'i18n17': ('{% load i18n %}{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α &amp; β'),
777  
-            'i18n18': ('{% load i18n %}{% blocktrans with anton|force_escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α &amp; β'),
  780
+            'i18n18': ('{% load i18n %}{% blocktrans with anton|escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α &amp; β'),
  781
+            'i18n19': ('{% load i18n %}{% blocktrans with anton|force_escape as berta %}{{ berta }}{% endblocktrans %}', {'anton': 'α & β'}, u'α &amp; β'),
778 782
 
779 783
             ### HANDLING OF TEMPLATE_STRING_IF_INVALID ###################################
780 784
 

0 notes on commit 6d863fe

Please sign in to comment.
Something went wrong with that request. Please try again.