Fixed #22717 -- Auto-corrected missing ending slash in FileSystemStorage
Thanks David Fischer for the report and Moayad Mardini for the review.
This commit is contained in:
parent
083d285b82
commit
fb9d8f0652
|
@ -159,6 +159,8 @@ class FileSystemStorage(Storage):
|
||||||
self.location = abspathu(self.base_location)
|
self.location = abspathu(self.base_location)
|
||||||
if base_url is None:
|
if base_url is None:
|
||||||
base_url = settings.MEDIA_URL
|
base_url = settings.MEDIA_URL
|
||||||
|
elif not base_url.endswith('/'):
|
||||||
|
base_url += '/'
|
||||||
self.base_url = base_url
|
self.base_url = base_url
|
||||||
self.file_permissions_mode = (
|
self.file_permissions_mode = (
|
||||||
file_permissions_mode if file_permissions_mode is not None
|
file_permissions_mode if file_permissions_mode is not None
|
||||||
|
|
|
@ -96,7 +96,7 @@ class FileStorageTests(unittest.TestCase):
|
||||||
shutil.rmtree(self.temp_dir)
|
shutil.rmtree(self.temp_dir)
|
||||||
shutil.rmtree(self.temp_dir2)
|
shutil.rmtree(self.temp_dir2)
|
||||||
|
|
||||||
def test_emtpy_location(self):
|
def test_empty_location(self):
|
||||||
"""
|
"""
|
||||||
Makes sure an exception is raised if the location is empty
|
Makes sure an exception is raised if the location is empty
|
||||||
"""
|
"""
|
||||||
|
@ -239,6 +239,14 @@ class FileStorageTests(unittest.TestCase):
|
||||||
self.storage.base_url = None
|
self.storage.base_url = None
|
||||||
self.assertRaises(ValueError, self.storage.url, 'test.file')
|
self.assertRaises(ValueError, self.storage.url, 'test.file')
|
||||||
|
|
||||||
|
# #22717: missing ending slash in base_url should be auto-corrected
|
||||||
|
storage = self.storage_class(location=self.temp_dir,
|
||||||
|
base_url='/no_ending_slash')
|
||||||
|
self.assertEqual(
|
||||||
|
storage.url('test.file'),
|
||||||
|
'%s%s' % (storage.base_url, 'test.file')
|
||||||
|
)
|
||||||
|
|
||||||
def test_listdir(self):
|
def test_listdir(self):
|
||||||
"""
|
"""
|
||||||
File storage returns a tuple containing directories and files.
|
File storage returns a tuple containing directories and files.
|
||||||
|
|
Loading…
Reference in New Issue