Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.3.1
-
None
-
None
-
Any
Description
When a FieldStorage has two (or more) Filed instances with the same value but
different names, the behaviour of programs like this is (more or less) undefined:
fs = util.FieldStorage(req)
fs['id1'] = 'New value'
del fs['id2']
The reason for the undefinedness, is this code in _delitem_ (and the similar
in _setitem_):
table = self.list.table()
values = table[key]
for value in values:
self.list.remove(value)
What happens is that the self.list.remove(value) will remove the first field
with a matching value, regardless of that fields name. Here is an example from
real life:
form.clear()
form['id1'] = 'x'
form['id2'] = 'x'
form['id3'] = 'x'
- Form now contains
{'id2': [Field('id2', 'x')],
# 'id3': [Field('id3', 'x')],
# 'id1': [Field('id1', 'x')]}
form['id2'] = 'y'
- Form now contains {'id2': [Field('id2', 'x'), Field('id2', 'y')], # 'id3': [Field('id3', 'x')]}
- which is not what I would have expected