diff --git a/redirect.py b/redirect.py index 3476858..771a144 100644 --- a/redirect.py +++ b/redirect.py @@ -48,7 +48,7 @@ def redir(to): domains = set((util.domain_from_link(to), urllib.parse.urlparse(to).hostname)) for domain in domains: - if MagicKey.get_by_id(domain): + if domain and MagicKey.get_by_id(domain): logging.info(f'Found MagicKey for domain {domain}') break else: diff --git a/tests/test_redirect.py b/tests/test_redirect.py index 01bc97d..11623dd 100644 --- a/tests/test_redirect.py +++ b/tests/test_redirect.py @@ -39,6 +39,10 @@ class RedirectTest(testutil.TestCase): self.assertEqual(301, got.status_code) self.assertEqual('https://foo.com/bar', got.headers['Location']) + def test_redirect_trailing_garbage_chars(self): + got = self.client.get(r'/r/https://v2.jacky.wtf\"') + self.assertEqual(404, got.status_code) + def test_as2(self): self._test_as2(common.CONTENT_TYPE_AS2)