Skip to content

Commit

Permalink
Merge pull request #5 from hakanw/respect_empty_media_url
Browse files Browse the repository at this point in the history
make sure no media path is prepended if there is no MEDIA_URL setting set in django
  • Loading branch information
ricobl committed Apr 12, 2016
2 parents d3e31a7 + 17683ab commit bebffa1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django_thumbor/__init__.py
Expand Up @@ -19,7 +19,7 @@ def _remove_schema(url):


def _prepend_media_url(url):
if url.startswith(settings.MEDIA_URL):
if settings.MEDIA_URL and url.startswith(settings.MEDIA_URL):
url = _remove_prefix(url, settings.MEDIA_URL)
url.lstrip('/')
return '%s/%s' % (conf.THUMBOR_MEDIA_URL, url)
Expand Down
4 changes: 4 additions & 0 deletions testproject/tests/test_generate_url.py
Expand Up @@ -93,6 +93,10 @@ def test_should_prepend_the_domain_to_media_url_images(self):
self.assertURLEquals('/media/uploads/image.jpg',
'localhost:8000/media/uploads/image.jpg')

@override_settings(MEDIA_URL="")
def test_should_not_prepend_media_url_if_none_is_set(self):
self.assertURLEquals('http://www.domain.com/media/uploads/image.jpg', 'www.domain.com/media/uploads/image.jpg')

def test_should_remove_the_scheme_from_external_images(self):
self.assertURLEquals('http://some.domain.com/path/image.jpg',
'some.domain.com/path/image.jpg')

0 comments on commit bebffa1

Please sign in to comment.