Browse code

Url encode source for copy/mv/modify to support all special/foreign character names in object names

Florent Viard authored on 2020/04/14 06:29:34
Showing 2 changed files
... ...
@@ -11,7 +11,7 @@ from logging import debug, info, warning, error
11 11
 from .Exceptions import ParameterError
12 12
 from .S3Uri import S3UriS3
13 13
 from .Utils import (getTextFromXml, getTreeFromXml, formatSize,
14
-                    calculateChecksum, parseNodes)
14
+                    calculateChecksum, parseNodes, s3_quote)
15 15
 
16 16
 
17 17
 class MultiPartUpload(object):
... ...
@@ -262,6 +262,10 @@ class MultiPartUpload(object):
262 262
         headers = {
263 263
             "x-amz-copy-source": "/%s/%s" % (self.src_uri.bucket(),
264 264
                                              self.src_uri.object()),
265
+            "x-amz-copy-source": s3_quote("/%s/%s" % (self.src_uri.bucket(),
266
+                                                      self.src_uri.object()),
267
+                                          quote_backslashes=False,
268
+                                          unicode_output=True)
265 269
         }
266 270
 
267 271
         # byte range, with end byte included. A 10 byte file has bytes=0-9
... ...
@@ -861,10 +861,10 @@ class S3(object):
861 861
                                                 headers, extra_label)
862 862
 
863 863
         ## Not multipart...
864
-        headers['x-amz-copy-source'] = "/%s/%s" % (
865
-            src_uri.bucket(),
866
-            urlencode_string(src_uri.object(), unicode_output=True)
867
-        )
864
+        headers['x-amz-copy-source'] = s3_quote("/%s/%s" % (src_uri.bucket(),
865
+                                                            src_uri.object()),
866
+                                                quote_backslashes=False,
867
+                                                unicode_output=True)
868 868
         headers['x-amz-metadata-directive'] = "COPY"
869 869
 
870 870
         request = self.create_request("OBJECT_PUT", uri=dst_uri,
... ...
@@ -908,8 +908,10 @@ class S3(object):
908 908
                 raise exc
909 909
             acl = None
910 910
 
911
-        headers['x-amz-copy-source'] = "/%s/%s" % (src_uri.bucket(),
912
-                                                   urlencode_string(src_uri.object(), unicode_output=True))
911
+        headers['x-amz-copy-source'] = s3_quote("/%s/%s" % (src_uri.bucket(),
912
+                                                            src_uri.object()),
913
+                                                quote_backslashes=False,
914
+                                                unicode_output=True)
913 915
         headers['x-amz-metadata-directive'] = "REPLACE"
914 916
 
915 917
         # cannot change between standard and reduced redundancy with a REPLACE.