]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: add test for unicode POST when the name comes from name=, not the filename attribute
authorBrian Warner <warner@allmydata.com>
Wed, 4 Jun 2008 00:09:39 +0000 (17:09 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 4 Jun 2008 00:09:39 +0000 (17:09 -0700)
src/allmydata/test/test_web.py
src/allmydata/web/directory.py

index 5ae18a51f8cc24de9f7fd4483a7f17d5b3231819..f5da33edd759b90a2f8face5d41d12cee3617225 100644 (file)
@@ -254,7 +254,12 @@ class WebMixin(object):
             else:
                 form.append('Content-Disposition: form-data; name="%s"' % name)
             form.append('')
-            form.append(str(value))
+            if isinstance(value, unicode):
+                value = value.encode("utf-8")
+            else:
+                value = str(value)
+            assert isinstance(value, str)
+            form.append(value)
             form.append(sep)
         form[-1] += "--"
         body = "\r\n".join(form) + "\r\n"
@@ -975,7 +980,6 @@ class Web(WebMixin, unittest.TestCase):
 
     def test_POST_upload_unicode(self):
         filename = u"n\u00e9wer.txt" # n e-acute w e r . t x t
-        target_url = self.public_url + "/foo/" + filename.encode("utf-8")
         d = self.POST(self.public_url + "/foo", t="upload",
                       file=(filename, self.NEWFILE_CONTENTS))
         fn = self._foo_node
@@ -983,6 +987,24 @@ class Web(WebMixin, unittest.TestCase):
         d.addCallback(lambda res:
                       self.failUnlessChildContentsAre(fn, filename,
                                                       self.NEWFILE_CONTENTS))
+        target_url = self.public_url + "/foo/" + filename.encode("utf-8")
+        d.addCallback(lambda res: self.GET(target_url))
+        d.addCallback(lambda contents: self.failUnlessEqual(contents,
+                                                            self.NEWFILE_CONTENTS,
+                                                            contents))
+        return d
+
+    def test_POST_upload_unicode_named(self):
+        filename = u"n\u00e9wer.txt" # n e-acute w e r . t x t
+        d = self.POST(self.public_url + "/foo", t="upload",
+                      name=filename,
+                      file=("overridden", self.NEWFILE_CONTENTS))
+        fn = self._foo_node
+        d.addCallback(self.failUnlessURIMatchesChild, fn, filename)
+        d.addCallback(lambda res:
+                      self.failUnlessChildContentsAre(fn, filename,
+                                                      self.NEWFILE_CONTENTS))
+        target_url = self.public_url + "/foo/" + filename.encode("utf-8")
         d.addCallback(lambda res: self.GET(target_url))
         d.addCallback(lambda contents: self.failUnlessEqual(contents,
                                                             self.NEWFILE_CONTENTS,
index 7a3473d9cfeed096f4fae3d8283486b2fd668ae4..f0218c470c5c1568c0d5a8a0a148b32d19149641 100644 (file)
@@ -234,6 +234,7 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
         req = IRequest(ctx)
         charset = get_arg(req, "_charset", "utf-8")
         contents = req.fields["file"]
+        assert contents.filename is None or isinstance(contents.filename, str)
         name = get_arg(req, "name")
         name = name or contents.filename
         if name is not None:
@@ -241,6 +242,7 @@ class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
         if not name:
             # this prohibts empty, missing, and all-whitespace filenames
             raise WebError("upload requires a name")
+        assert isinstance(name, str)
         name = name.decode(charset)
         if "/" in name:
             raise WebError("name= may not contain a slash", http.BAD_REQUEST)