Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
db63355c
Commit
db63355c
authored
May 27, 2010
by
Martin Aspeli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix processInputs() so that it no longer stomps on things like :records or :int:list
parent
3297779b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
13 deletions
+70
-13
doc/CHANGES.rst
doc/CHANGES.rst
+4
-0
src/Products/Five/browser/decode.py
src/Products/Five/browser/decode.py
+30
-13
src/Products/Five/browser/tests/test_decode.py
src/Products/Five/browser/tests/test_decode.py
+36
-0
No files found.
doc/CHANGES.rst
View file @
db63355c
...
@@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/.
...
@@ -11,6 +11,10 @@ http://docs.zope.org/zope2/releases/.
Bugs Fixed
Bugs Fixed
++++++++++
++++++++++
- Five's processInputs() would stomp on :list or :tuple values that contained
ints or other non-strings, would clear out :records entirely, and would not
do anything for :record fields.
- LP #143261: The (very old-fashioned) Zope2.debug interactive request
- LP #143261: The (very old-fashioned) Zope2.debug interactive request
debugger still referred to the toplevel module ``Zope``, which was
debugger still referred to the toplevel module ``Zope``, which was
renamed to ``Zope2`` a long time ago.
renamed to ``Zope2`` a long time ago.
...
...
src/Products/Five/browser/decode.py
View file @
db63355c
...
@@ -32,23 +32,40 @@ def _decode(text, charsets):
...
@@ -32,23 +32,40 @@ def _decode(text, charsets):
pass
pass
return
text
return
text
def
processInputValue
(
value
,
charsets
):
"""Recursively look for values (e.g. elements of lists, tuples or dicts)
and attempt to decode.
"""
if
isinstance
(
value
,
list
):
return
[
processInputValue
(
v
,
charsets
)
for
v
in
value
]
elif
isinstance
(
value
,
tuple
):
return
tuple
([
processInputValue
(
v
,
charsets
)
for
v
in
value
])
elif
isinstance
(
value
,
dict
):
for
k
,
v
in
value
.
items
():
value
[
k
]
=
processInputValue
(
v
,
charsets
)
return
value
elif
isinstance
(
value
,
str
):
return
_decode
(
value
,
charsets
)
else
:
return
value
def
processInputs
(
request
,
charsets
=
None
):
def
processInputs
(
request
,
charsets
=
None
):
"""Process the values in request.form to decode strings to unicode, using
the passed-in list of charsets. If none are passed in, look up the user's
preferred charsets. The default is to use utf-8.
"""
if
charsets
is
None
:
if
charsets
is
None
:
envadapter
=
IUserPreferredCharsets
(
request
)
envadapter
=
IUserPreferredCharsets
(
request
,
None
)
if
envadapter
is
None
:
charsets
=
[
'utf-8'
]
else
:
charsets
=
envadapter
.
getPreferredCharsets
()
or
[
'utf-8'
]
charsets
=
envadapter
.
getPreferredCharsets
()
or
[
'utf-8'
]
for
name
,
value
in
request
.
form
.
items
():
for
name
,
value
in
request
.
form
.
items
():
if
not
(
isCGI_NAME
(
name
)
or
name
.
startswith
(
'HTTP_'
)):
if
not
(
isCGI_NAME
(
name
)
or
name
.
startswith
(
'HTTP_'
)):
if
isinstance
(
value
,
str
):
request
.
form
[
name
]
=
processInputValue
(
value
,
charsets
)
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
):
def
setPageEncoding
(
request
):
"""Set the encoding of the form page via the Content-Type header.
"""Set the encoding of the form page via the Content-Type header.
...
...
src/Products/Five/browser/tests/test_decode.py
View file @
db63355c
...
@@ -46,6 +46,42 @@ def test_processInputs():
...
@@ -46,6 +46,42 @@ def test_processInputs():
>>> processInputs(request, charsets)
>>> processInputs(request, charsets)
>>> request.form['foo'] == (u'f
\
xf6
\
xf6
',)
>>> request.form['foo'] == (u'f
\
xf6
\
xf6
',)
True
True
Ints in lists are not lost::
>>> request.form['foo'] = [1, 2, 3]
>>> processInputs(request, charsets)
>>> request.form['foo'] == [1, 2, 3]
True
Ints in tuples are not lost::
>>> request.form['foo'] = (1, 2, 3,)
>>> processInputs(request, charsets)
>>> request.form['foo'] == (1, 2, 3)
True
Mixed lists work:
>>> request.form['foo'] = [u'f
\
xf6
\
xf6
'.encode('iso-8859-1'), 2, 3]
>>> processInputs(request, charsets)
>>> request.form['foo'] == [u'f
\
xf6
\
xf6
', 2, 3]
True
Mixed dicts work:
>>> request.form['foo'] = {'foo': u'f
\
xf6
\
xf6
'.encode('iso-8859-1'), 'bar': 2}
>>> processInputs(request, charsets)
>>> request.form['foo'] == {'foo': u'f
\
xf6
\
xf6
', 'bar': 2}
True
Deep recursion works:
>>> request.form['foo'] = [{'foo': u'f
\
xf6
\
xf6
'.encode('iso-8859-1'), 'bar': 2}, {'foo': u"one", 'bar': 3}]
>>> processInputs(request, charsets)
>>> request.form['foo'] == [{'foo': u'f
\
xf6
\
xf6
', 'bar': 2}, {'foo': u"one", 'bar': 3}]
True
"""
"""
def
test_suite
():
def
test_suite
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment