Django

Code

Ticket #6071: 6813_SafeString_Updates.patch

File 6813_SafeString_Updates.patch, 2.7 kB (added by trey, 1 year ago)
  • django/utils/safestring.py

    old new  
    3434        Concatenating a safe string with another safe string or safe unicode 
    3535        object is safe. Otherwise, the result is no longer safe. 
    3636        """ 
     37        t = super(SafeString, self).__add__(rhs) 
    3738        if isinstance(rhs, SafeUnicode): 
    38             return SafeUnicode(self + rhs
     39            return SafeUnicode(t
    3940        elif isinstance(rhs, SafeString): 
    40             return SafeString(self + rhs) 
    41         else: 
    42             return super(SafeString, self).__add__(rhs) 
    43  
     41            return SafeString(t) 
     42        return t 
     43         
    4444    def _proxy_method(self, *args, **kwargs): 
    4545        """ 
    4646        Wrap a call to a normal unicode method up so that we return safe 
     
    6666        Concatenating a safe unicode object with another safe string or safe 
    6767        unicode object is safe. Otherwise, the result is no longer safe. 
    6868        """ 
     69        t = super(SafeUnicode, self).__add__(rhs) 
    6970        if isinstance(rhs, SafeData): 
    70             return SafeUnicode(self + rhs) 
    71         else: 
    72             return super(SafeUnicode, self).__add__(rhs) 
    73  
     71            return SafeUnicode(t) 
     72        return t 
     73     
    7474    def _proxy_method(self, *args, **kwargs): 
    7575        """ 
    7676        Wrap a call to a normal unicode method up so that we return safe 
  • tests/regressiontests/i18n/tests.py

    old new  
    4343Translating a string requiring no auto-escaping shouldn't change the "safe" 
    4444status. 
    4545 
    46 >>> from django.utils.safestring import mark_safe 
     46>>> from django.utils.safestring import mark_safe, SafeString 
    4747>>> s = mark_safe('Password') 
    4848>>> type(s) 
    4949<class 'django.utils.safestring.SafeString'> 
     
    5151>>> type(ugettext(s)) 
    5252<class 'django.utils.safestring.SafeUnicode'> 
    5353>>> deactivate() 
     54 
     55>>> SafeString('a') + s 
     56'aPassword' 
     57>>> s + SafeString('a') 
     58'Passworda' 
     59>>> s + mark_safe('a') 
     60'Passworda' 
     61>>> mark_safe('a') + s 
     62'aPassword' 
     63>>> mark_safe('a') + mark_safe('s') 
     64'as' 
     65>>> print s 
     66Password 
    5467""" 
    5568 
    5669__test__ = { 
  • AUTHORS

    old new  
    204204    Waylan Limberg <waylan@gmail.com> 
    205205    limodou 
    206206    Philip Lindborg <philip.lindborg@gmail.com> 
     207    Trey Long <trey@ktrl.com> 
    207208    msaelices <msaelices@gmail.com> 
    208209    Matt McClanahan <http://mmcc.cx/> 
    209210    Martin Maney <http://www.chipy.org/Martin_Maney>