aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg
diff options
context:
space:
mode:
authorDennis Fink2026-11-13 07:44:10 +0100
committerDennis Fink2026-11-13 07:44:10 +0100
commitab018f5e4405dc6a3ee214744344ffda73c1fc6f (patch)
tree06390ada60e632b9ac6324ea4b7015a40d3360e7 /webmentions_ssg
parent52fc66cb5ff19bf0def001ae50acc1b465a0b977 (diff)
downloadwebmentions-ssg-ab018f5e4405dc6a3ee214744344ffda73c1fc6f.tar.gz
webmentions-ssg-ab018f5e4405dc6a3ee214744344ffda73c1fc6f.zip
refactor(core): inline endpoint source comparison
Remove the generic cross-field equality validator and keep the source-versus-target check directly on `EndpointForm`, where the validation rule is actually used.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/forms.py51
1 files changed, 5 insertions, 46 deletions
diff --git a/webmentions_ssg/forms.py b/webmentions_ssg/forms.py
index d557907..af24423 100644
--- a/webmentions_ssg/forms.py
+++ b/webmentions_ssg/forms.py
@@ -72,51 +72,6 @@ class HTTPXURL:
raise StopValidation(field.gettext("Invalid URL."))
-class NotEqualTo:
- """Validate that a field does not equal another field.
-
- :param fieldname: Name of the field to compare against.
- :param message: Optional validation error message.
- """
-
- def __init__(self, fieldname: str, message: str | None = None) -> None:
- """Initialize the validator.
-
- :param fieldname: Name of the field to compare against.
- :param message: Optional validation error message.
- """
- self.fieldname = fieldname
- self.message = message
-
- def __call__(self, form: BaseForm, field: Field) -> None:
- """Validate that two fields do not contain equal values.
-
- :param form: Form containing the fields to compare.
- :param field: Field being validated.
- :raises ValidationError: If the comparison field does not exist or both
- fields contain equal values.
- """
- try:
- other = form[self.fieldname]
- except KeyError as exc:
- raise ValidationError(
- field.gettext("Invalid field name '%s'.") % self.fieldname
- ) from exc
-
- if field.data != other.data:
- return
-
- d = {
- "other_label": (hasattr(other, "label") and other.label.text)
- or self.fieldname,
- "other_name": self.fieldname,
- }
- message = self.message or field.gettext(
- "Field must not be equal to %(other_name)s."
- )
- raise ValidationError(message % d)
-
-
class AllowedHostname:
"""Validate that a URL uses an allowed hostname.
@@ -194,7 +149,6 @@ class EndpointForm(FlaskForm):
flags=re.IGNORECASE,
message="source must begin with http or https",
),
- NotEqualTo("target"),
PublicIPLiteral(),
],
)
@@ -214,6 +168,11 @@ class EndpointForm(FlaskForm):
],
)
+ def validate_source(self, field: Field) -> None:
+ """Reject a source URL that equals the target URL."""
+ if field.data == self.target.data:
+ raise ValidationError(field.gettext("Field must not be equal to target."))
+
class AdminActionForm(FlaskForm):
"""Form for confirming an administrative action."""