summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-05-28 19:03:26 +0200
committerClaude Paroz <claude@2xlibre.net>2014-06-04 08:53:17 +0200
commitfb9d8f06520f495d0c36236f7534dbe660c7e164 (patch)
treeb13fc4bc02ff0c090665cb9efe17642442395d6c
parent083d285b82832f95b57c64144020cc2ce8895a22 (diff)
Fixed #22717 -- Auto-corrected missing ending slash in FileSystemStorage
Thanks David Fischer for the report and Moayad Mardini for the review.
-rw-r--r--django/core/files/storage.py2
-rw-r--r--tests/file_storage/tests.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index 98864f7f22..a36440ab4c 100644
--- a/django/core/files/storage.py
+++ b/django/core/files/storage.py
@@ -159,6 +159,8 @@ class FileSystemStorage(Storage):
self.location = abspathu(self.base_location)
if base_url is None:
base_url = settings.MEDIA_URL
+ elif not base_url.endswith('/'):
+ base_url += '/'
self.base_url = base_url
self.file_permissions_mode = (
file_permissions_mode if file_permissions_mode is not None
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 392cd871c3..da9410d70f 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -96,7 +96,7 @@ class FileStorageTests(unittest.TestCase):
shutil.rmtree(self.temp_dir)
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
"""
@@ -239,6 +239,14 @@ class FileStorageTests(unittest.TestCase):
self.storage.base_url = None
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):
"""
File storage returns a tuple containing directories and files.