From: Brian Warner Date: Wed, 4 Jun 2008 00:09:39 +0000 (-0700) Subject: web: add test for unicode POST when the name comes from name=, not the filename attribute X-Git-Tag: allmydata-tahoe-1.1.0~50 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/...?a=commitdiff_plain;h=0aa6d24d62f79225f52fd578c660e0d04a81d024;p=tahoe-lafs%2Ftahoe-lafs.git web: add test for unicode POST when the name comes from name=, not the filename attribute --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 5ae18a51..f5da33ed 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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, diff --git a/src/allmydata/web/directory.py b/src/allmydata/web/directory.py index 7a3473d9..f0218c47 100644 --- a/src/allmydata/web/directory.py +++ b/src/allmydata/web/directory.py @@ -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)