Remove unnecessary exceptions from validate_url_domain

This commit is contained in:
Bart Schuurmans 2024-04-02 14:27:47 +02:00
parent 3d183a393f
commit c73d1fff6a
2 changed files with 2 additions and 9 deletions

View file

@ -25,7 +25,3 @@ class TestUtils(TestCase):
self.assertIsNone(
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("/"), "/")

View file

@ -4,14 +4,11 @@ from typing import Optional
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"""
if not url:
if url is None:
return None
if url == "/":
return url
protocol = "https://" if USE_HTTPS else "http://"
origin = f"{protocol}{DOMAIN}"