Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@malcolmt malcolmt authored
View
1  AUTHORS
@@ -207,6 +207,7 @@ answer newbie questions, and generally made Django that much better:
Waylan Limberg <waylan@gmail.com>
limodou
Philip Lindborg <philip.lindborg@gmail.com>
+ Trey Long <trey@ktrl.com>
msaelices <msaelices@gmail.com>
Matt McClanahan <http://mmcc.cx/>
Martin Maney <http://www.chipy.org/Martin_Maney>
View
18 django/utils/safestring.py
@@ -34,13 +34,13 @@ def __add__(self, rhs):
Concatenating a safe string with another safe string or safe unicode
object is safe. Otherwise, the result is no longer safe.
"""
+ t = super(SafeString, self).__add__(rhs)
if isinstance(rhs, SafeUnicode):
- return SafeUnicode(self + rhs)
+ return SafeUnicode(t)
elif isinstance(rhs, SafeString):
- return SafeString(self + rhs)
- else:
- return super(SafeString, self).__add__(rhs)
-
+ return SafeString(t)
+ return t
+
def _proxy_method(self, *args, **kwargs):
"""
Wrap a call to a normal unicode method up so that we return safe
@@ -66,11 +66,11 @@ def __add__(self, rhs):
Concatenating a safe unicode object with another safe string or safe
unicode object is safe. Otherwise, the result is no longer safe.
"""
+ t = super(SafeUnicode, self).__add__(rhs)
if isinstance(rhs, SafeData):
- return SafeUnicode(self + rhs)
- else:
- return super(SafeUnicode, self).__add__(rhs)
-
+ return SafeUnicode(t)
+ return t
+
def _proxy_method(self, *args, **kwargs):
"""
Wrap a call to a normal unicode method up so that we return safe
View
15 tests/regressiontests/i18n/tests.py
@@ -43,7 +43,7 @@
Translating a string requiring no auto-escaping shouldn't change the "safe"
status.
->>> from django.utils.safestring import mark_safe
+>>> from django.utils.safestring import mark_safe, SafeString
>>> s = mark_safe('Password')
>>> type(s)
<class 'django.utils.safestring.SafeString'>
@@ -51,6 +51,19 @@
>>> type(ugettext(s))
<class 'django.utils.safestring.SafeUnicode'>
>>> deactivate()
+
+>>> SafeString('a') + s
+'aPassword'
+>>> s + SafeString('a')
+'Passworda'
+>>> s + mark_safe('a')
+'Passworda'
+>>> mark_safe('a') + s
+'aPassword'
+>>> mark_safe('a') + mark_safe('s')
+'as'
+>>> print s
+Password
"""
__test__ = {
Please sign in to comment.
Something went wrong with that request. Please try again.