mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-16 19:15:16 +00:00
Remove unnecessary exceptions from validate_url_domain
This commit is contained in:
parent
3d183a393f
commit
c73d1fff6a
2 changed files with 2 additions and 9 deletions
|
@ -25,7 +25,3 @@ class TestUtils(TestCase):
|
||||||
self.assertIsNone(
|
self.assertIsNone(
|
||||||
validate_url_domain("https://up-to-no-good.tld/bad-actor.exe")
|
validate_url_domain("https://up-to-no-good.tld/bad-actor.exe")
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_default_url_domain(self):
|
|
||||||
"""Check with a default URL"""
|
|
||||||
self.assertEqual(validate_url_domain("/"), "/")
|
|
||||||
|
|
|
@ -4,14 +4,11 @@ from typing import Optional
|
||||||
from bookwyrm.settings import DOMAIN, USE_HTTPS
|
from bookwyrm.settings import DOMAIN, USE_HTTPS
|
||||||
|
|
||||||
|
|
||||||
def validate_url_domain(url: str) -> Optional[str]:
|
def validate_url_domain(url: Optional[str]) -> Optional[str]:
|
||||||
"""Basic check that the URL starts with the instance domain name"""
|
"""Basic check that the URL starts with the instance domain name"""
|
||||||
if not url:
|
if url is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if url == "/":
|
|
||||||
return url
|
|
||||||
|
|
||||||
protocol = "https://" if USE_HTTPS else "http://"
|
protocol = "https://" if USE_HTTPS else "http://"
|
||||||
origin = f"{protocol}{DOMAIN}"
|
origin = f"{protocol}{DOMAIN}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue