Skip to content

Commit

Permalink
Merge pull request #800 from Fausterkun/add_allow_ip_at_url_validator
Browse files Browse the repository at this point in the history
add allow_ip flag availability from URL validator
  • Loading branch information
azmeuk authored Oct 1, 2023
2 parents 60ab1a9 + 7c56b6f commit 1afceb2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/wtforms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<host>[^\/\?:]+)"
Expand All @@ -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):
Expand Down

0 comments on commit 1afceb2

Please sign in to comment.