mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-23 14:52:26 +00:00
web: add test for unicode POST when the name comes from name=, not the filename attribute
This commit is contained in:
parent
9f5075e83d
commit
0aa6d24d62
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user