diff --git a/swift/container/backend.py b/swift/container/backend.py index 977ae7a79f..d41f297acf 100644 --- a/swift/container/backend.py +++ b/swift/container/backend.py @@ -776,7 +776,7 @@ class ContainerBroker(DatabaseBroker): marker = name[:end] + chr(ord(delimiter) + 1) curs.close() break - elif end > 0: + elif end >= 0: if reverse: end_marker = name[:end + 1] else: diff --git a/test/functional/tests.py b/test/functional/tests.py index d51156e7c2..35339e68ec 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -618,6 +618,20 @@ class TestContainer(Base): 'reverse': 'yes'}) self.assertEqual(results, ['baza', 'bar']) + def testLeadingDelimiter(self): + cont = self.env.account.container(Utils.create_name()) + self.assertTrue(cont.create()) + + delimiter = '/' + files = ['test', delimiter.join(['', 'test', 'bar']), + delimiter.join(['', 'test', 'bar', 'foo'])] + for f in files: + file_item = cont.file(f) + self.assertTrue(file_item.write_random()) + + results = cont.files(parms={'delimiter': delimiter}) + self.assertEqual(results, [delimiter, 'test']) + def testCreate(self): cont = self.env.account.container(Utils.create_name()) self.assertTrue(cont.create()) diff --git a/test/unit/container/test_backend.py b/test/unit/container/test_backend.py index 8e521f0078..be1fdcbff2 100644 --- a/test/unit/container/test_backend.py +++ b/test/unit/container/test_backend.py @@ -1539,6 +1539,9 @@ class TestContainerBroker(unittest.TestCase): listing = broker.list_objects_iter(100, None, None, '/pets/fish/', '/') self.assertEqual([row[0] for row in listing], ['/pets/fish/a', '/pets/fish/b']) + listing = broker.list_objects_iter(100, None, None, None, '/') + self.assertEqual([row[0] for row in listing], + ['/']) def test_list_objects_iter_order_and_reverse(self): # Test ContainerBroker.list_objects_iter diff --git a/test/unit/container/test_server.py b/test/unit/container/test_server.py index fd0e5a5633..3802fcb05b 100644 --- a/test/unit/container/test_server.py +++ b/test/unit/container/test_server.py @@ -2359,6 +2359,30 @@ class TestContainerController(unittest.TestCase): {"subdir": "US-TX-"}, {"subdir": "US-UT-"}]) + def test_GET_leading_delimiter(self): + req = Request.blank( + '/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT', + 'HTTP_X_TIMESTAMP': '0'}) + resp = req.get_response(self.controller) + for i in ('US-TX-A', 'US-TX-B', '-UK', '-CH'): + req = Request.blank( + '/sda1/p/a/c/%s' % i, + environ={ + 'REQUEST_METHOD': 'PUT', 'HTTP_X_TIMESTAMP': '1', + 'HTTP_X_CONTENT_TYPE': 'text/plain', 'HTTP_X_ETAG': 'x', + 'HTTP_X_SIZE': 0}) + self._update_object_put_headers(req) + resp = req.get_response(self.controller) + self.assertEqual(resp.status_int, 201) + req = Request.blank( + '/sda1/p/a/c?delimiter=-&format=json', + environ={'REQUEST_METHOD': 'GET'}) + resp = req.get_response(self.controller) + self.assertEqual( + json.loads(resp.body), + [{"subdir": "-"}, + {"subdir": "US-"}]) + def test_GET_delimiter_xml(self): req = Request.blank( '/sda1/p/a/c', environ={'REQUEST_METHOD': 'PUT',