Commits

Anonymous committed 3c1bb2b

Fixed `Headers.set` (#354). Caused header duplication before.

  • Participants
  • Parent commits b0af059

Comments (0)

Files changed (3)

 - Fixed `BaseCache.get_dict` (#345)
 - `werkzeug.test.Client` can now run the application buffered in which
   case the application is properly closed automatically.
+- Fixed `Headers.set` (#354).  Caused header duplication before.
 
 Version 0.4
 -----------

File tests/test_utils.py

            validate_arguments, take_none, (1,), {}, drop_extra=False)
     raises(ArgumentValidationError,
            validate_arguments, take_none, (), {'a': 1}, drop_extra=False)
+
+
+def test_header_set_duplication_bug():
+    headers = Headers([
+        ('Content-Type', 'text/html'),
+        ('Foo', 'bar'),
+        ('Blub', 'blah')
+    ])
+    headers['blub'] = 'hehe'
+    headers['blafasel'] = 'humm'
+    assert headers == Headers([
+        ('Content-Type', 'text/html'),
+        ('Foo', 'bar'),
+        ('blub', 'hehe'),
+        ('blafasel', 'humm')
+    ])

File werkzeug/utils.py

         lc_key = key.lower()
         for idx, (old_key, old_value) in enumerate(self._list):
             if old_key.lower() == lc_key:
+                # replace first ocurrence
                 self._list[idx] = (key, value)
                 break
         else:
             return self.add(key, value)
-        self._list[idx + 1:] = [(k, v) for k, v in self._list
+        self._list[idx + 1:] = [(k, v) for k, v in self._list[idx + 1:]
                                 if k.lower() != lc_key]
 
     def __setitem__(self, key, value):