1
0
Fork 0

Add validation util + test

This commit is contained in:
Joachim 2022-12-30 17:55:47 +01:00
parent 5c92774a7f
commit bfe04feca9
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,16 @@
"""Validations"""
from bookwyrm.settings import DOMAIN, USE_HTTPS
def validate_url_domain(url, default="/"):
"""Basic check that the URL starts with the instance domain name"""
if url in ("/", default):
return url
protocol = "https://" if USE_HTTPS else "http://"
origin = f"{protocol}{DOMAIN}"
if url.startswith(origin):
return url
return default