diff --git a/AUTHORS b/AUTHORS index 5965b728a8..d976f7dc5d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -207,6 +207,7 @@ answer newbie questions, and generally made Django that much better: Waylan Limberg limodou Philip Lindborg + Trey Long msaelices Matt McClanahan Martin Maney diff --git a/django/utils/safestring.py b/django/utils/safestring.py index d8e44d7d09..2e31c23676 100644 --- a/django/utils/safestring.py +++ b/django/utils/safestring.py @@ -34,13 +34,13 @@ class SafeString(str, SafeData): 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 @@ class SafeUnicode(unicode, SafeData): 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 diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py index 2ffc62f90d..94e792cf54 100644 --- a/tests/regressiontests/i18n/tests.py +++ b/tests/regressiontests/i18n/tests.py @@ -43,7 +43,7 @@ u'django' 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) @@ -51,6 +51,19 @@ status. >>> type(ugettext(s)) >>> 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__ = {