[1.6.x] Do not allow FileSystemStorage.delete to receive an empty name
Refs #20660.
Backport of 7fbab3eba
from master.
This commit is contained in:
parent
b6aed803b2
commit
a9b5a1e506
|
@ -231,6 +231,7 @@ class FileSystemStorage(Storage):
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def delete(self, name):
|
def delete(self, name):
|
||||||
|
assert name, "The name argument is not allowed to be empty."
|
||||||
name = self.path(name)
|
name = self.path(name)
|
||||||
# If the file exists, delete it from the filesystem.
|
# If the file exists, delete it from the filesystem.
|
||||||
# Note that there is a race between os.path.exists and os.remove:
|
# Note that there is a race between os.path.exists and os.remove:
|
||||||
|
|
|
@ -364,6 +364,14 @@ class FileStorageTests(unittest.TestCase):
|
||||||
with self.assertRaises(IOError):
|
with self.assertRaises(IOError):
|
||||||
self.storage.save('error.file', f1)
|
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):
|
class CustomStorage(FileSystemStorage):
|
||||||
def get_available_name(self, name):
|
def get_available_name(self, name):
|
||||||
|
|
Loading…
Reference in New Issue