summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-06-27 10:59:30 +0200
committerClaude Paroz <claude@2xlibre.net>2013-06-29 18:09:31 +0200
commit7fbab3ebaf8b60bbe847b772f895df47067a60d3 (patch)
treec8339ec8c88035c2d5882044c47f1f11afb2b9ec
parentea3fe78a9d742904f6902cdc353a11d795418105 (diff)
Do not allow FileSystemStorage.delete to receive an empty name
Refs #20660.
-rw-r--r--django/core/files/storage.py1
-rw-r--r--tests/file_storage/tests.py8
2 files changed, 9 insertions, 0 deletions
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 977b6a68a8..5d301a317c 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -231,6 +231,7 @@ class FileSystemStorage(Storage):
return name
def delete(self, name):
+ assert name, "The name argument is not allowed to be empty."
name = self.path(name)
# If the file exists, delete it from the filesystem.
# Note that there is a race between os.path.exists and os.remove:
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 6c3c559660..e6caabf9d9 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -364,6 +364,14 @@ class FileStorageTests(unittest.TestCase):
with self.assertRaises(IOError):
self.storage.save('error.file', f1)
+ def test_delete_no_name(self):
+ """
+ Calling delete with an empty name should not try to remove the base
+ storage directory, but fail loudly (#20660).
+ """
+ with self.assertRaises(AssertionError):
+ self.storage.delete('')
+
class CustomStorage(FileSystemStorage):
def get_available_name(self, name):