]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: handle initial slashes properly in BulkDelete of Swift API. 8164/head
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Tue, 15 Mar 2016 15:48:26 +0000 (16:48 +0100)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 20 May 2016 10:55:47 +0000 (12:55 +0200)
Fixes: http://tracker.ceph.com/issues/15948
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_rest_swift.cc

index 734f78bcd2b0887ba7d5c37102665e38f013c219..b971c320cc33f960ffa9cb50116fc2ffc8fd1cdc 100644 (file)
@@ -1152,22 +1152,32 @@ int RGWBulkDelete_ObjStore_SWIFT::get_data(
 
     RGWBulkDelete::acct_path_t path;
 
-    const size_t sep_pos = path_str.find('/');
-    if (string::npos == sep_pos) {
-      url_decode(path_str, path.bucket_name);
-    } else {
-      string bucket_name;
-      url_decode(path_str.substr(0, sep_pos), bucket_name);
-
-      string obj_name;
-      url_decode(path_str.substr(sep_pos + 1), obj_name);
+    /* We need to skip all slashes at the beginning in order to preserve
+     * compliance with Swift. */
+    const size_t start_pos = path_str.find_first_not_of('/');
+
+    if (string::npos != start_pos) {
+      /* Seperator is the first slash after the leading ones. */
+      const size_t sep_pos = path_str.find('/', start_pos);
+
+      if (string::npos != sep_pos) {
+        string bucket_name;
+        url_decode(path_str.substr(start_pos, sep_pos - start_pos), bucket_name);
+
+        string obj_name;
+        url_decode(path_str.substr(sep_pos + 1), obj_name);
+
+        path.bucket_name = bucket_name;
+        path.obj_key = obj_name;
+      } else {
+        /* It's guaranteed here that bucket name is at least one character
+         * long and is different than slash. */
+        url_decode(path_str.substr(start_pos), path.bucket_name);
+      }
 
-      path.bucket_name = bucket_name;
-      path.obj_key = obj_name;
+      items.push_back(path);
     }
 
-    items.push_back(path);
-
     if (items.size() == MAX_CHUNK_ENTRIES) {
       *is_truncated = true;
       return 0;