Skip to content

Commit

Permalink
Merge 1083508 into 8db42f1
Browse files Browse the repository at this point in the history
  • Loading branch information
sallner committed Aug 11, 2017
2 parents 8db42f1 + 1083508 commit c694c02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/zope/formlib/_compat.py
Expand Up @@ -35,8 +35,14 @@ def safeBase64Encode(obj):

from StringIO import StringIO
from itertools import imap
unicode = toUnicode = unicode
unicode = unicode
basestring = basestring

def toUnicode(obj):
if isinstance(obj, bytes):
return unicode(obj, 'utf-8')
else:
return unicode(obj)

def safeBase64Encode(obj):
return base64.b64encode(toUnicode(obj)).strip().replace('=', '_')
9 changes: 9 additions & 0 deletions src/zope/formlib/tests/test_textwidget.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2001, 2002, 2004, 2005 Zope Foundation and Contributors.
Expand Down Expand Up @@ -132,6 +133,14 @@ def testRender(self):
self._widget.extra = 'style="color: red"'
self.verifyResult(self._widget.hidden(), check_list)

def testRenderUTF8Input(self):
value = u"☃".encode('utf-8') # results in \u2603
self._widget.setRenderedValue(value)
check_list = ('type="text"', 'id="field.foo"', 'name="field.foo"',
u'value="\u2603"', 'size="20"')
self.verifyResult(self._widget(), check_list)


class URIDisplayWidgetTest(BrowserWidgetTest):

_WidgetFactory = URIDisplayWidget
Expand Down

0 comments on commit c694c02

Please sign in to comment.