]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
tahoe_cp.py: Don't call urllib.quote with an Unicode argument, fix #1224
authorFrancois Deppierraz <francois@ctrlaltdel.ch>
Sat, 16 Oct 2010 09:09:22 +0000 (11:09 +0200)
committerBrian Warner <warner@lothar.com>
Fri, 29 Oct 2010 08:45:20 +0000 (01:45 -0700)
tahoe_backup.py: Fix another (potential) occurrence of calling urllib.quote()
with an Unicode parameter

src/allmydata/scripts/tahoe_backup.py
src/allmydata/scripts/tahoe_cp.py
src/allmydata/test/test_cli.py

index badc35e36a682667ed815ae85a85af56790fc9c8..26279e0c431a3d7cb8b0763baab89d6b75f9b6fa 100644 (file)
@@ -50,7 +50,7 @@ def mkdir(contents, options):
 
 def put_child(dirurl, childname, childcap):
     assert dirurl[-1] == "/"
-    url = dirurl + urllib.quote(childname) + "?t=uri"
+    url = dirurl + urllib.quote(unicode_to_url(childname)) + "?t=uri"
     resp = do_http("PUT", url, childcap)
     if resp.status not in (200, 201):
         raise HTTPError("Error during put_child", resp)
index 4c41db049b0e11e53dfc146d7d9d4d20436f6268..9f9100421ff18c7ef6ef47517a15c565aede033c 100644 (file)
@@ -51,7 +51,7 @@ def mkdir(targeturl):
 def make_tahoe_subdirectory(nodeurl, parent_writecap, name):
     url = nodeurl + "/".join(["uri",
                               urllib.quote(parent_writecap),
-                              urllib.quote(name),
+                              urllib.quote(unicode_to_url(name)),
                               ]) + "?t=mkdir"
     resp = do_http("POST", url)
     if resp.status in (200, 201):
index 245312607468fc1941f0a9ad7db43392c53cb535..d9e34c2a99759d0cdbcb8ee66bd98698fb1c2ea6 100644 (file)
@@ -1487,6 +1487,39 @@ class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
         d.addCallback(_check)
         return d
 
+    def test_unicode_dirnames(self):
+        self.basedir = "cli/Cp/unicode_dirnames"
+
+        fn1 = os.path.join(unicode(self.basedir), u"\u00C4rtonwall")
+        try:
+            fn1_arg = fn1.encode(get_argv_encoding())
+            artonwall_arg = u"\u00C4rtonwall".encode(get_argv_encoding())
+        except UnicodeEncodeError:
+            raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
+
+        self.skip_if_cannot_represent_filename(fn1)
+
+        self.set_up_grid()
+
+        d = self.do_cli("create-alias", "tahoe")
+        d.addCallback(lambda res: self.do_cli("mkdir", "tahoe:test/" + artonwall_arg))
+        d.addCallback(lambda res: self.do_cli("cp", "-r", "tahoe:test", "tahoe:test2"))
+        d.addCallback(lambda res: self.do_cli("ls", "tahoe:test2"))
+        def _check((rc, out, err)):
+            try:
+                unicode_to_output(u"\u00C4rtonwall")
+            except UnicodeEncodeError:
+                self.failUnlessReallyEqual(rc, 1)
+                self.failUnlessReallyEqual(out, "")
+                self.failUnlessIn(quote_output(u"\u00C4rtonwall"), err)
+                self.failUnlessIn("files whose names could not be converted", err)
+            else:
+                self.failUnlessReallyEqual(rc, 0)
+                self.failUnlessReallyEqual(out.decode(get_output_encoding()), u"\u00C4rtonwall\n")
+                self.failUnlessReallyEqual(err, "")
+        d.addCallback(_check)
+
+        return d
 
 class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):