Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-256

util.FieldStorage __setitem__/__delitem__ might affect wrong field

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.3.1
    • None
    • core
    • 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'

      1. Form now contains {'id2': [Field('id2', 'x')], # 'id3': [Field('id3', 'x')], # 'id1': [Field('id1', 'x')]}

        form['id2'] = 'y'

      2. Form now contains {'id2': [Field('id2', 'x'), Field('id2', 'y')], # 'id3': [Field('id3', 'x')]}
      3. which is not what I would have expected

      Attachments

        1. modpython.patch
          1 kB
          Anders Blomdell

        Activity

          People

            Unassigned Unassigned
            anders.blomdell@control.lth.se Anders Blomdell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: