# HG changeset patch # User Brian Neal # Date 1445802449 18000 # Node ID 26de15fb5a80884d4b65626ed18a5181f77ff45c # Parent 9b197dbba34bc99e9537769b5502fbed90ec7f52 Guard against bad image urls in ssl_images. diff -r 9b197dbba34b -r 26de15fb5a80 core/management/commands/ssl_images.py --- a/core/management/commands/ssl_images.py Sun Oct 25 13:54:56 2015 -0500 +++ b/core/management/commands/ssl_images.py Sun Oct 25 14:47:29 2015 -0500 @@ -191,7 +191,11 @@ new_src = None if src: - r = urlparse.urlparse(src) + try: + r = urlparse.urlparse(src) + except ValueError: + return u'{bad image}' + if r.hostname in SG101_HOSTS: new_src = r.path # convert to relative path elif r.scheme == 'http': diff -r 9b197dbba34b -r 26de15fb5a80 core/tests/test_ssl_images.py --- a/core/tests/test_ssl_images.py Sun Oct 25 13:54:56 2015 -0500 +++ b/core/tests/test_ssl_images.py Sun Oct 25 14:47:29 2015 -0500 @@ -234,6 +234,15 @@ expected_args = [mock.call(urlparse(c)) for c in old_src[:2]] self.assertEqual(upload_mock.call_args_list, expected_args) + @mock.patch('core.management.commands.ssl_images.save_image_to_cloud') + def test_bad_image_url(self, upload_mock): + test_str = u'![image](http://[url=http://www.flickr.com/photos/85447101@N04/8025176073/][img]http://farm9.staticflickr.com/8456/8025176073_91ac0c3d18_b.jpg[/img][/url] [url=http://www.flickr.com/photos/85447101@N04/8025176073/]IMG_0398[/url] by [url=http://www.flickr.com/people/85447101@N04/]friendshipmaster[/url], on Flick)' + expected = u'{bad image}' + + result = process_post(test_str) + self.assertEqual(expected, result) + self.assertEqual(upload_mock.call_count, 0) + class HtmlCheckTestCase(unittest.TestCase):