Commits

Ian Lewis committed e643ba6 Merge

Merged in mmlin/django-storages (pull request #72)

For the s3 and s3boto backends, the 'url' methods remove trailing slashes but should not. This fixes that.

  • Participants
  • Parent commits 513c418, 544e36f

Comments (0)

Files changed (3)

storages/backends/s3.py

File contents unchanged.

storages/backends/s3boto.py

         return parse_ts_extended(entry.last_modified)
 
     def url(self, name, headers=None, response_headers=None):
-        name = self._normalize_name(self._clean_name(name))
+        # Preserve the trailing slash after normalizing the path.
+        trailing_slash = '/' if name.endswith('/') else ''
+        name = self._normalize_name(self._clean_name(name)) + trailing_slash
         if self.custom_domain:
             return "%s//%s/%s" % (self.url_protocol,
                                   self.custom_domain, filepath_to_uri(name))

storages/tests/s3boto.py

 
 class S3BotoStorageTests(S3BotoTestCase):
 
+    def test_storage_url(self):
+        """
+        Test URL generation.
+        """
+        self.storage.custom_domain = 'example.com'
+
+        # We expect no leading slashes in the path,
+        # and trailing slashes should be preserved.
+        self.assertEqual(self.storage.url(''), 'https://example.com/')
+        self.assertEqual(self.storage.url('path'), 'https://example.com/path')
+        self.assertEqual(self.storage.url('path/'), 'https://example.com/path/')
+        self.assertEqual(self.storage.url('path/1'), 'https://example.com/path/1')
+        self.assertEqual(self.storage.url('path/1/'), 'https://example.com/path/1/')
+
     def test_storage_save(self):
         """
         Test saving a file