Ticket #6071: 6813_SafeString_Updates.patch
File 6813_SafeString_Updates.patch, 2.7 KB (added by , 17 years ago) |
---|
-
django/utils/safestring.py
34 34 Concatenating a safe string with another safe string or safe unicode 35 35 object is safe. Otherwise, the result is no longer safe. 36 36 """ 37 t = super(SafeString, self).__add__(rhs) 37 38 if isinstance(rhs, SafeUnicode): 38 return SafeUnicode( self + rhs)39 return SafeUnicode(t) 39 40 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 44 44 def _proxy_method(self, *args, **kwargs): 45 45 """ 46 46 Wrap a call to a normal unicode method up so that we return safe … … 66 66 Concatenating a safe unicode object with another safe string or safe 67 67 unicode object is safe. Otherwise, the result is no longer safe. 68 68 """ 69 t = super(SafeUnicode, self).__add__(rhs) 69 70 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 74 74 def _proxy_method(self, *args, **kwargs): 75 75 """ 76 76 Wrap a call to a normal unicode method up so that we return safe -
tests/regressiontests/i18n/tests.py
43 43 Translating a string requiring no auto-escaping shouldn't change the "safe" 44 44 status. 45 45 46 >>> from django.utils.safestring import mark_safe 46 >>> from django.utils.safestring import mark_safe, SafeString 47 47 >>> s = mark_safe('Password') 48 48 >>> type(s) 49 49 <class 'django.utils.safestring.SafeString'> … … 51 51 >>> type(ugettext(s)) 52 52 <class 'django.utils.safestring.SafeUnicode'> 53 53 >>> 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 66 Password 54 67 """ 55 68 56 69 __test__ = { -
AUTHORS
204 204 Waylan Limberg <waylan@gmail.com> 205 205 limodou 206 206 Philip Lindborg <philip.lindborg@gmail.com> 207 Trey Long <trey@ktrl.com> 207 208 msaelices <msaelices@gmail.com> 208 209 Matt McClanahan <http://mmcc.cx/> 209 210 Martin Maney <http://www.chipy.org/Martin_Maney>