[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ Fix bug https://bugs.launchpad.net/z3c.dav/+bug/163150 - trying to copy / move

Michael Kerrin michael.kerrin at openapp.ie
Sat Nov 17 12:27:35 EST 2007


Log message for revision 81895:
  Fix bug https://bugs.launchpad.net/z3c.dav/+bug/163150 - trying to copy / move
  to a destination containing with a quoted character caused a ConflictError.
  

Changed:
  U   z3c.dav/trunk/src/z3c/dav/copymove.py
  U   z3c.dav/trunk/src/z3c/dav/ftests/test_copymove.py
  U   z3c.dav/trunk/src/z3c/dav/tests/test_copymove.py

-=-
Modified: z3c.dav/trunk/src/z3c/dav/copymove.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/copymove.py	2007-11-17 17:22:21 UTC (rev 81894)
+++ z3c.dav/trunk/src/z3c/dav/copymove.py	2007-11-17 17:27:35 UTC (rev 81895)
@@ -19,6 +19,7 @@
 """
 __docformat__ = 'restructuredtext'
 
+import urllib
 import urlparse
 
 from zope import interface
@@ -73,7 +74,7 @@
                 raise z3c.dav.interfaces.BadGateway(
                     self.context, self.request)
 
-        return destpath
+        return urllib.unquote(destpath).decode("utf-8")
 
     def getDestinationNameAndParentObject(self):
         """Returns a tuple for destionation name, the parent folder object

Modified: z3c.dav/trunk/src/z3c/dav/ftests/test_copymove.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/ftests/test_copymove.py	2007-11-17 17:22:21 UTC (rev 81894)
+++ z3c.dav/trunk/src/z3c/dav/ftests/test_copymove.py	2007-11-17 17:27:35 UTC (rev 81895)
@@ -173,7 +173,41 @@
                                             "http://localhost/c")
         self.assertEqual(list(self.getRootFolder()["c"].keys()), [u"r2", u"r3"])
 
+    def test_copy_with_space_in_dest_filename(self):
+        file = self.addResource("/source file", "some file content",
+                                contentType = "text/plain")
 
+        response = self.publish(
+            "/source file", basic = "mgr:mgrpw",
+            env = {"REQUEST_METHOD": "COPY",
+                   "DESTINATION": "http://localhost/dest file"})
+
+        self.assertEqual(response.getStatus(), 201)
+        self.assertEqual(response.getHeader("location"),
+                         "http://localhost/dest%20file")
+        self.assertEqual(self.getRootFolder()["dest file"].data,
+                         "some file content")
+        self.assertEqual(self.getRootFolder()["source file"].data,
+                         "some file content")
+
+    def test_copy_with_quotedspace_in_dest_filename(self):
+        file = self.addResource("/source file", "some file content",
+                                contentType = "text/plain")
+
+        response = self.publish(
+            "/source file", basic = "mgr:mgrpw",
+            env = {"REQUEST_METHOD": "COPY",
+                   "DESTINATION": "http://localhost/dest%20file"})
+
+        self.assertEqual(response.getStatus(), 201)
+        self.assertEqual(response.getHeader("location"),
+                         "http://localhost/dest%20file")
+        self.assertEqual(self.getRootFolder()["dest file"].data,
+                         "some file content")
+        self.assertEqual(self.getRootFolder()["source file"].data,
+                         "some file content")
+
+
 class MOVETestCase(dav.DAVTestCase):
     """These tests are very similar to the COPY tests. Actually I copied them
     and modified them to work with MOVE.
@@ -327,7 +361,39 @@
                                             "http://localhost/c")
         self.assertEqual(list(self.getRootFolder()["c"].keys()), [u"r2", u"r3"])
 
+    def test_move_with_space_in_dest_filename(self):
+        file = self.addResource("/source file", "some file content",
+                                contentType = "text/plain")
 
+        response = self.publish(
+            "/source file", basic = "mgr:mgrpw",
+            env = {"REQUEST_METHOD": "MOVE",
+                   "DESTINATION": "http://localhost/dest file"})
+
+        self.assertEqual(response.getStatus(), 201)
+        self.assertEqual(response.getHeader("location"),
+                         "http://localhost/dest%20file")
+        self.assertEqual(self.getRootFolder()["dest file"].data,
+                         "some file content")
+        self.assert_("source file" not in self.getRootFolder())
+
+    def test_move_with_quotedspace_in_dest_filename(self):
+        file = self.addResource("/source file", "some file content",
+                                contentType = "text/plain")
+
+        response = self.publish(
+            "/source file", basic = "mgr:mgrpw",
+            env = {"REQUEST_METHOD": "MOVE",
+                   "DESTINATION": "http://localhost/dest%20file"})
+
+        self.assertEqual(response.getStatus(), 201)
+        self.assertEqual(response.getHeader("location"),
+                         "http://localhost/dest%20file")
+        self.assertEqual(self.getRootFolder()["dest file"].data,
+                         "some file content")
+        self.assert_("source file" not in self.getRootFolder())
+
+
 def test_suite():
     return unittest.TestSuite((
             unittest.makeSuite(COPYTestCase),

Modified: z3c.dav/trunk/src/z3c/dav/tests/test_copymove.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/test_copymove.py	2007-11-17 17:22:21 UTC (rev 81894)
+++ z3c.dav/trunk/src/z3c/dav/tests/test_copymove.py	2007-11-17 17:27:35 UTC (rev 81895)
@@ -32,7 +32,7 @@
 from zope.traversing.interfaces import IContainmentRoot
 
 import z3c.dav.publisher
-from z3c.dav.copymove import COPY, MOVE
+from z3c.dav.copymove import Base, COPY, MOVE
 
 class IResource(interface.Interface):
 
@@ -215,6 +215,28 @@
         self.assertRaises(z3c.dav.interfaces.BadGateway,
                           copy.getDestinationNameAndParentObject)
 
+    def test_getDestinationPath_with_space(self):
+        resource = self.root["resource"] = Resource()
+        request = TestRequest(
+            environ = {"DESTINATION": "http://localhost/test path"})
+
+        copy = Base(resource, request)
+        destname, destob, parent = copy.getDestinationNameAndParentObject()
+        self.assertEqual(destname, "test path")
+        self.assertEqual(destob, None)
+        self.assertEqual(parent, self.root)
+
+    def test_getDestinationPath_with_quotedspace(self):
+        resource = self.root["resource"] = Resource()
+        request = TestRequest(
+            environ = {"DESTINATION": "http://localhost/test%20path"})
+
+        copy = Base(resource, request)
+        destname, destob, parent = copy.getDestinationNameAndParentObject()
+        self.assertEqual(destname, "test path")
+        self.assertEqual(destob, None)
+        self.assertEqual(parent, self.root)
+
     def test_getDestinationNameAndParentObject(self):
         resource = self.root["resource"] = Resource()
         request = TestRequest(



More information about the Checkins mailing list