[Zope-Checkins] SVN: Products.Five/branches/1.4/ - processInputs
did not decode strings in lists and tuples
Yvo Schubbe
y.2006_ at wcm-solutions.de
Wed Oct 25 15:20:29 EDT 2006
Log message for revision 70913:
- processInputs did not decode strings in lists and tuples
Changed:
U Products.Five/branches/1.4/CHANGES.txt
UU Products.Five/branches/1.4/browser/decode.py
A Products.Five/branches/1.4/browser/tests/test_decode.py
-=-
Modified: Products.Five/branches/1.4/CHANGES.txt
===================================================================
--- Products.Five/branches/1.4/CHANGES.txt 2006-10-25 12:01:35 UTC (rev 70912)
+++ Products.Five/branches/1.4/CHANGES.txt 2006-10-25 19:20:28 UTC (rev 70913)
@@ -8,6 +8,8 @@
Bugfixes
--------
+* browser: processInputs now decodes strings in lists and tuples.
+
* formlib: Removed redundant subpageform.pt and backported pageform.pt fixes
from Zope 3. Added missing error view and i18n configuration.
Modified: Products.Five/branches/1.4/browser/decode.py
===================================================================
--- Products.Five/branches/1.4/browser/decode.py 2006-10-25 12:01:35 UTC (rev 70912)
+++ Products.Five/branches/1.4/browser/decode.py 2006-10-25 19:20:28 UTC (rev 70913)
@@ -13,6 +13,8 @@
##############################################################################
""" Utility functions for decoding browser input and setting the output
encoding.
+
+$Id$
"""
from zope.publisher.browser import isCGI_NAME
@@ -34,11 +36,19 @@
if charsets is None:
envadapter = IUserPreferredCharsets(request)
charsets = envadapter.getPreferredCharsets() or ['utf-8']
-
+
for name, value in request.form.items():
- if (not (isCGI_NAME(name) or name.startswith('HTTP_'))
- and isinstance(value, str)):
- request.form[name] = _decode(value, charsets)
+ if not (isCGI_NAME(name) or name.startswith('HTTP_')):
+ if isinstance(value, str):
+ request.form[name] = _decode(value, charsets)
+ elif isinstance(value, list):
+ request.form[name] = [ _decode(val, charsets)
+ for val in value
+ if isinstance(val, str) ]
+ elif isinstance(value, tuple):
+ request.form[name] = tuple([ _decode(val, charsets)
+ for val in value
+ if isinstance(val, str) ])
def setPageEncoding(request):
"""Set the encoding of the form page via the Content-Type header.
Property changes on: Products.Five/branches/1.4/browser/decode.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: Products.Five/branches/1.4/browser/tests/test_decode.py
===================================================================
--- Products.Five/branches/1.4/browser/tests/test_decode.py 2006-10-25 12:01:35 UTC (rev 70912)
+++ Products.Five/branches/1.4/browser/tests/test_decode.py 2006-10-25 19:20:28 UTC (rev 70913)
@@ -0,0 +1,59 @@
+##############################################################################
+#
+# 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$
+"""
+import os, sys
+if __name__ == '__main__':
+ execfile(os.path.join(sys.path[0], 'framework.py'))
+
+def test_processInputs():
+ """
+ Testing processInputs
+
+ >>> from Products.Five.browser.decode import processInputs
+ >>> charsets = ['iso-8859-1']
+ >>> class DummyRequest:
+ ... form = {}
+ >>> request = DummyRequest()
+
+ Strings are converted to unicode::
+
+ >>> request.form['foo'] = u'f\xf6\xf6'.encode('iso-8859-1')
+ >>> processInputs(request, charsets)
+ >>> 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')]
+ >>> processInputs(request, charsets)
+ >>> 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'),)
+ >>> processInputs(request, charsets)
+ >>> request.form['foo'] == (u'f\xf6\xf6',)
+ True
+ """
+
+def test_suite():
+ from zope.testing.doctest import DocTestSuite
+ return DocTestSuite()
+
+if __name__ == '__main__':
+ framework()
Property changes on: Products.Five/branches/1.4/browser/tests/test_decode.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
More information about the Zope-Checkins
mailing list