#8966: {% if "x"|length_is:n %} always evaluates True
---------------------------------------------------------+------------------
          Reporter:  Thomas Steinacher <[EMAIL PROTECTED]>  |         Owner:  
nobody
            Status:  new                                 |     Milestone:       
 
         Component:  Uncategorized                       |       Version:  SVN  
 
        Resolution:                                      |      Keywords:       
 
             Stage:  Unreviewed                          |     Has_patch:  1    
 
        Needs_docs:  0                                   |   Needs_tests:  0    
 
Needs_better_patch:  0                                   |  
---------------------------------------------------------+------------------
Changes (by carljm):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * summary:  {% if "x"|capfirst|length_is:n %} always evaluates True => {%
              if "x"|length_is:n %} always evaluates True
  * version:  1.0 => SVN
  * needs_docs:  => 0
  * has_patch:  0 => 1

Comment:

 capfirst is irrelevant.  This also fails:

 {{{
 >>> Template('{% if "x"|length_is:0 %}Wrong{% endif
 %}').render(Context({}))
 u'Wrong'
 }}}

 Changed summary to reflect this.  Also changed version to SVN, as this
 problem is still present in trunk.

 The problem here is that the is_safe attribute is set on the length_is
 tag, which causes mark_safe to be called on the return value, and
 mark_safe(False) returns the string 'False'.  Not sure where in that chain
 is the proper place for the fix.  It's possible that mark_safe needs to be
 smart about not always coercing its argument to a string, or
 FilterExpression.resolve needs to check if the return value is a string
 before calling mark_safe on it.  But the naive fix is just to remove the
 is_safe attribute from length_is, since auto-escaping will never harm its
 return value.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8966#comment:1>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to