Skip to content
Snippets Groups Projects
Commit 13503e62 authored by Felix Schäfer's avatar Felix Schäfer :construction_worker:
Browse files

Gracefully handle non-hostname matrix servers #16

parent 4e76cc37
No related branches found
No related tags found
No related merge requests found
Pipeline #171274 passed
from django.core.exceptions import ValidationError
from django.forms import (
CharField,
CheckboxSelectMultiple,
......@@ -7,6 +8,8 @@ from django.forms import (
from django.utils.translation import gettext_lazy
from i18nfield.forms import I18nFormField, I18nTextInput
from pretix.base.forms import SettingsForm
from urllib3.exceptions import LocationParseError
from urllib3.util import parse_url
from .helpers import matrix_room_info_for_event
......@@ -58,6 +61,14 @@ class MatrixInviterSettingsForm(SettingsForm):
strip=True,
)
def clean_matrix_inviter_matrix_server(self):
url = self.cleaned_data["matrix_inviter_matrix_server"]
try:
return parse_url(url).host
except LocationParseError:
raise ValidationError("Please enter a valid hostname")
return url
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["matrix_inviter_items"].choices = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment