aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/forms
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 21:20:40 +0100
committerDennis Fink2026-11-13 21:20:40 +0100
commita285fdf29e59c3b957247ea9241943c7202e9a28 (patch)
tree17ceeb703de23af1e67081d99a8864bbe353fb46 /webmentions_ssg/forms
parent78ecd8bc227bdcbbd0e45eea025f7223252ed0da (diff)
downloadwebmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.tar.gz
webmentions-ssg-a285fdf29e59c3b957247ea9241943c7202e9a28.zip
refactor(core): consolidate repeated helper logic
Centralize SQL row counts, hostname parsing, and content-type normalization so tasks, forms, and scanners share consistent implementations. Simplify periodic task registration and admin lookups with table-driven setup and Flask-SQLAlchemy's built-in 404 helper.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/forms.py14
1 files changed, 3 insertions, 11 deletions
diff --git a/webmentions_ssg/forms.py b/webmentions_ssg/forms.py
index 005bd20..f5fba51 100644
--- a/webmentions_ssg/forms.py
+++ b/webmentions_ssg/forms.py
@@ -5,7 +5,6 @@
"""Webmention forms and URL validation."""
import ipaddress
-from urllib.parse import urlsplit
import httpx
from flask import current_app
@@ -14,7 +13,7 @@ from wtforms import Field, PasswordField, StringField, SubmitField, ValidationEr
from wtforms.form import BaseForm
from wtforms.validators import InputRequired, StopValidation
-from .net import is_public_address
+from .net import hostname_of, is_public_address
from .validation import is_control_character
@@ -96,10 +95,7 @@ class AllowedHostname:
:param field: Field containing the URL to validate.
:raises ValidationError: If the URL hostname is not configured as allowed.
"""
- try:
- hostname = (urlsplit(field.data).hostname or "").rstrip(".")
- except ValueError, TypeError:
- hostname = None
+ hostname = hostname_of(field.data)
if hostname is not None and hostname in current_app.config["ALLOWED_HOSTNAMES"]:
return
raise ValidationError(self.message or field.gettext("Invalid input."))
@@ -109,11 +105,7 @@ class PublicIPLiteral:
"""Reject non-public IP literals without performing DNS in the web worker."""
def __call__(self, form: BaseForm, field: Field) -> None:
- try:
- hostname = urlsplit(field.data).hostname
- except (ValueError, TypeError) as exc:
- raise ValidationError(field.gettext("Invalid input.")) from exc
-
+ hostname = hostname_of(field.data)
if hostname is None:
raise ValidationError(field.gettext("Invalid input."))