From 7c56b6f69a66d9e9d0578a323ae0ec74b4e1f43e Mon Sep 17 00:00:00 2001 From: Fausterkun Date: Mon, 31 Jul 2023 18:06:31 +0300 Subject: [PATCH] add allow_ip flag availability from URL validator --- src/wtforms/validators.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wtforms/validators.py b/src/wtforms/validators.py index 3c0db3b09..730ba17ae 100644 --- a/src/wtforms/validators.py +++ b/src/wtforms/validators.py @@ -511,11 +511,13 @@ class URL(Regexp): If true, then the domain-name portion of the URL must contain a .tld suffix. Set this to false if you want to allow domains like `localhost`. + :param allow_ip: + If false, then give ip as host will fail validation :param message: Error message to raise in case of a validation error. """ - def __init__(self, require_tld=True, message=None): + def __init__(self, require_tld=True, allow_ip=True, message=None): regex = ( r"^[a-z]+://" r"(?P[^\/\?:]+)" @@ -525,7 +527,7 @@ def __init__(self, require_tld=True, message=None): ) super().__init__(regex, re.IGNORECASE, message) self.validate_hostname = HostnameValidation( - require_tld=require_tld, allow_ip=True + require_tld=require_tld, allow_ip=allow_ip ) def __call__(self, form, field):