Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6071 -- Fixed another infinite recursion problem in SafeString…

… and

SafeUnicode. Thanks, Trey Long.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@6845 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 2e62b84accc25b5ced9641850736ab66fc6092c7 1 parent 51dc4ec
Malcolm Tredinnick authored December 02, 2007
1  AUTHORS
@@ -207,6 +207,7 @@ answer newbie questions, and generally made Django that much better:
207 207
     Waylan Limberg <waylan@gmail.com>
208 208
     limodou
209 209
     Philip Lindborg <philip.lindborg@gmail.com>
  210
+    Trey Long <trey@ktrl.com>
210 211
     msaelices <msaelices@gmail.com>
211 212
     Matt McClanahan <http://mmcc.cx/>
212 213
     Martin Maney <http://www.chipy.org/Martin_Maney>
18  django/utils/safestring.py
@@ -34,13 +34,13 @@ def __add__(self, rhs):
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,11 +66,11 @@ def __add__(self, rhs):
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
15  tests/regressiontests/i18n/tests.py
@@ -43,7 +43,7 @@
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,6 +51,19 @@
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__ = {

0 notes on commit 2e62b84

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