Add validation util + test
This commit is contained in:
parent
5c92774a7f
commit
bfe04feca9
2 changed files with 34 additions and 0 deletions
16
bookwyrm/utils/validate.py
Normal file
16
bookwyrm/utils/validate.py
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue