fix: escape the dash in URL regex (#1255)

This commit is contained in:
Trigam
2025-12-12 02:47:17 -05:00
committed by GitHub
parent 71d9fc6f3c
commit ccb16e970a

View File

@@ -34,9 +34,7 @@ class TextWidget(FieldWidget):
# Regex from https://stackoverflow.com/a/6041965
def linkify(text: str):
url_pattern = (
r"(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-*]*[\w@?^=%&\/~+#-*])"
)
url_pattern = r"(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#\-*]*[\w@?^=%&\/~+#\-*])" # noqa: E501
return re.sub(
url_pattern,
lambda url: f'<a href="{url.group(0)}">{url.group(0)}</a>',