[wsgi] Fix posted files filename reading
authorChristophe de Vienne <christophe@unlish.com>
Tue, 09 Sep 2014 22:14:20 +0200
changeset 9988 623707a0c404
parent 9987 bf4f5064c7f5
child 9989 cfb6e9dab902
[wsgi] Fix posted files filename reading The filenames are parsed by multipart.parse_form_data, which does the unicode decoding. Trying to re-decode the filename was leading to an error.
wsgi/request.py
wsgi/test/unittest_wsgi.py
--- a/wsgi/request.py	Tue Sep 23 11:18:56 2014 +0200
+++ b/wsgi/request.py	Tue Sep 09 22:14:20 2014 +0200
@@ -81,10 +81,7 @@
         self.content = environ['wsgi.input']
         if files is not None:
             for key, part in files.iteritems():
-                name = None
-                if part.filename is not None:
-                    name = unicode(part.filename, self.encoding)
-                self.form[key] = (name, part.file)
+                self.form[key] = (part.filename, part.file)
 
     def __repr__(self):
         # Since this is called as part of error handling, we need to be very
--- a/wsgi/test/unittest_wsgi.py	Tue Sep 23 11:18:56 2014 +0200
+++ b/wsgi/test/unittest_wsgi.py	Tue Sep 09 22:14:20 2014 +0200
@@ -78,6 +78,17 @@
 
         self.assertEqual([u'1', u'2'], req.form['arg'])
 
+    def test_post_files(self):
+        content_type, params = self.webapp.encode_multipart(
+            (), (('filefield', 'aname', 'acontent'),))
+        r = webtest.app.TestRequest.blank(
+            '/', POST=params, content_type=content_type)
+        req = CubicWebWsgiRequest(r.environ, self.vreg)
+        self.assertIn('filefield', req.form)
+        fieldvalue = req.form['filefield']
+        self.assertEqual(u'aname', fieldvalue[0])
+        self.assertEqual('acontent', fieldvalue[1].read())
+
     def test_post_unicode_urlencoded(self):
         params = 'arg=%C3%A9'
         r = webtest.app.TestRequest.blank(