From 82da3171cdf1e963fd72825aa50a6a97af0e6867 Mon Sep 17 00:00:00 2001 From: Anthony Ryan Date: Tue, 13 Jan 2015 08:44:33 -0500 Subject: [PATCH] sickbeard.config.clean_url may add trailing /'s in unsuitable circumstances Also adds some simple tests so we can avoid future regressions. --- sickbeard/config.py | 6 ++---- tests/config_tests.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 tests/config_tests.py diff --git a/sickbeard/config.py b/sickbeard/config.py index fd365ef0..b5217f18 100644 --- a/sickbeard/config.py +++ b/sickbeard/config.py @@ -326,10 +326,8 @@ def clean_url(url): scheme, netloc, path, query, fragment = urlparse.urlsplit(url, 'http') - if not path.endswith('/'): - basename, ext = ek.ek(os.path.splitext, ek.ek(os.path.basename, path)) # @UnusedVariable - if not ext: - path = path + '/' + if not path: + path = path + '/' cleaned_url = urlparse.urlunsplit((scheme, netloc, path, query, fragment)) diff --git a/tests/config_tests.py b/tests/config_tests.py new file mode 100644 index 00000000..8632f40b --- /dev/null +++ b/tests/config_tests.py @@ -0,0 +1,20 @@ +import unittest + +import sys +import os.path +sys.path.append(os.path.abspath('..')) + +from sickbeard import config + + +class QualityTests(unittest.TestCase): + + def test_clean_url(self): + self.assertEqual(config.clean_url("https://subdomain.domain.tld/endpoint"), "https://subdomain.domain.tld/endpoint") + self.assertEqual(config.clean_url("google.com/xml.rpc"), "http://google.com/xml.rpc") + self.assertEqual(config.clean_url("google.com"), "http://google.com/") + self.assertEqual(config.clean_url("http://www.example.com/folder/"), "http://www.example.com/folder/") + +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(QualityTests) + unittest.TextTestRunner(verbosity=2).run(suite)