Log message for revision 71059: Backported 'browser: processInputs now decodes strings in lists and tuples' fix from 1.4 (r70913) branch.
Changed: U Products.Five/branches/1.3/CHANGES.txt A Products.Five/branches/1.3/browser/tests/test_decode.py U Products.Five/branches/1.3/form/__init__.py -=- Modified: Products.Five/branches/1.3/CHANGES.txt =================================================================== --- Products.Five/branches/1.3/CHANGES.txt 2006-11-04 13:35:51 UTC (rev 71058) +++ Products.Five/branches/1.3/CHANGES.txt 2006-11-04 18:54:04 UTC (rev 71059) @@ -8,6 +8,8 @@ Bugfixes -------- +* browser: processInputs now decodes strings in lists and tuples. + * Port code from Zope 3 making resource directories recursive. Thanks to Richard Waid. Added: Products.Five/branches/1.3/browser/tests/test_decode.py =================================================================== --- Products.Five/branches/1.3/browser/tests/test_decode.py 2006-11-04 13:35:51 UTC (rev 71058) +++ Products.Five/branches/1.3/browser/tests/test_decode.py 2006-11-04 18:54:04 UTC (rev 71059) @@ -0,0 +1,75 @@ +############################################################################## +# +# Copyright (c) 2006 Zope Corporation and Contributors. +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +############################################################################## +"""Unit tests for decode module. + +$Id: test_decode.py 70913 2006-10-25 19:20:28Z yuppie $ +""" +import os, sys +if __name__ == '__main__': + execfile(os.path.join(sys.path[0], 'framework.py')) + +def test_processInputs(): + """ + Testing processInputs + + >>> from zope import interface + >>> from zope.i18n.interfaces import IUserPreferredCharsets + >>> from Products.Five.form import EditView + >>> class DummyResponse: + ... headers = {} + ... def setHeader(self, n, v): + ... self.headers[n] = v + >>> class DummyRequest: + ... interface.implements(IUserPreferredCharsets) + ... form = {} + ... def getPreferredCharsets(self): + ... return ['iso-8859-1'] + ... RESPONSE = DummyResponse() + >>> class DummyEditView(EditView): + ... def __init__(self, context, request): + ... self.context = context + ... self.request = request + >>> request = DummyRequest() + + Strings are converted to unicode:: + + >>> request.form['foo'] = u'f\xf6\xf6'.encode('iso-8859-1') + >>> editview = DummyEditView(None, request) + >>> editview._processInputs() + >>> request.form['foo'] == u'f\xf6\xf6' + True + + Strings in lists are converted to unicode:: + + >>> request.form['foo'] = [u'f\xf6\xf6'.encode('iso-8859-1')] + >>> editview = DummyEditView(None, request) + >>> editview._processInputs() + >>> request.form['foo'] == [u'f\xf6\xf6'] + True + + Strings in tuples are converted to unicode:: + + >>> request.form['foo'] = (u'f\xf6\xf6'.encode('iso-8859-1'),) + >>> editview = DummyEditView(None, request) + >>> editview._processInputs() + >>> request.form['foo'] == (u'f\xf6\xf6',) + True + """ + +def test_suite(): + from zope.testing.doctest import DocTestSuite + return DocTestSuite() + +if __name__ == '__main__': + framework() Modified: Products.Five/branches/1.3/form/__init__.py =================================================================== --- Products.Five/branches/1.3/form/__init__.py 2006-11-04 13:35:51 UTC (rev 71058) +++ Products.Five/branches/1.3/form/__init__.py 2006-11-04 18:54:04 UTC (rev 71059) @@ -88,9 +88,17 @@ def _processInputs(self): request = self.request for name, value in request.form.items(): - if (not (isCGI_NAME(name) or name.startswith('HTTP_')) - and isinstance(value, str)): - request.form[name] = self._decode(value) + if not (isCGI_NAME(name) or name.startswith('HTTP_')): + if isinstance(value, str): + request.form[name] = self._decode(value) + elif isinstance(value, list): + request.form[name] = [ self._decode(val) + for val in value + if isinstance(val, str) ] + elif isinstance(value, tuple): + request.form[name] = tuple([ self._decode(val) + for val in value + if isinstance(val, str) ]) def _setPageEncoding(self): """Set the encoding of the form page via the Content-Type header. _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins