Skip to content

Commit

Permalink
Change url quoting in boto3 to use python urllib quote
Browse files Browse the repository at this point in the history
  • Loading branch information
danielholmes committed Sep 18, 2018
1 parent cfa413a commit 71672e2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions storages/backends/s3boto.py
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime
from gzip import GzipFile
from tempfile import SpooledTemporaryFile
from urllib.parse import quote

from django.conf import settings as django_settings
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
Expand All @@ -13,7 +14,7 @@
from django.utils import timezone as tz
from django.utils.deconstruct import deconstructible
from django.utils.encoding import (
filepath_to_uri, force_bytes, force_text, smart_str,
force_bytes, force_text, smart_str,
)

from storages.utils import (
Expand Down Expand Up @@ -501,7 +502,7 @@ def url(self, name, headers=None, response_headers=None, expire=None):
name = self._normalize_name(self._clean_name(name))
if self.custom_domain:
return '%s//%s/%s' % (self.url_protocol,
self.custom_domain, filepath_to_uri(name))
self.custom_domain, quote(name))

if expire is None:
expire = self.querystring_expire
Expand Down
4 changes: 2 additions & 2 deletions tests/test_s3boto3.py
Expand Up @@ -507,11 +507,11 @@ def test_storage_url(self):

def test_generated_url_is_encoded(self):
self.storage.custom_domain = "mock.cloudfront.net"
filename = "whacky & filename.mp4"
filename = "whacky & filename'.mp4"
url = self.storage.url(filename)
parsed_url = urlparse.urlparse(url)
self.assertEqual(parsed_url.path,
"/whacky%20%26%20filename.mp4")
"/whacky%20%26%20filename%27.mp4")
self.assertFalse(self.storage.bucket.meta.client.generate_presigned_url.called)

def test_special_characters(self):
Expand Down

0 comments on commit 71672e2

Please sign in to comment.