Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #3314 -- Fixed a bug in newforms smart_unicode. Thanks for the …

…patch, nesh

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4522 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a13a47e447c925ad39f0c3a4bd5c2cddfc74d3d3 1 parent 6245816
Adrian Holovaty adrianholovaty authored
Showing with 27 additions and 1 deletion.
  1. +4 −1 django/newforms/util.py
  2. +23 −0 tests/regressiontests/forms/tests.py
5 django/newforms/util.py
View
@@ -7,7 +7,10 @@
def smart_unicode(s):
if not isinstance(s, basestring):
- s = unicode(str(s))
+ if hasattr(s, '__unicode__'):
+ s = unicode(s)
+ else:
+ s = unicode(str(s), settings.DEFAULT_CHARSET)
elif not isinstance(s, unicode):
s = unicode(s, settings.DEFAULT_CHARSET)
return s
23 tests/regressiontests/forms/tests.py
View
@@ -3265,6 +3265,29 @@
u''
>>> f.clean('')
u''
+
+#################################
+# Tests of underlying functions #
+#################################
+
+# smart_unicode tests
+>>> from django.newforms.util import smart_unicode
+>>> class Test:
+... def __str__(self):
+... return 'ŠĐĆŽćžšđ'
+>>> class TestU:
+... def __str__(self):
+... return 'Foo'
+... def __unicode__(self):
+... return u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+>>> smart_unicode(Test())
+u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+>>> smart_unicode(TestU())
+u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+>>> smart_unicode(1)
+u'1'
+>>> smart_unicode('foo')
+u'foo'
"""
if __name__ == "__main__":
Please sign in to comment.
Something went wrong with that request. Please try again.