Skip to content

Commit

Permalink
URL validator passes with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
laurihy committed Nov 5, 2019
1 parent 1ef6329 commit 150f16e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/wtforms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class URL(Regexp):
"""

def __init__(self, require_tld=True, message=None):
regex = r"^[a-z]+://(?P<host>[^/:]+)(?P<port>:[0-9]+)?(?P<path>\/.*)?$"
regex = r"^[a-z]+://(?P<host>[^\/\?:]+)(?P<port>:[0-9]+)?(?P<path>\/.*?)?(?P<query>\?.*)?$"
super(URL, self).__init__(regex, re.IGNORECASE, message)
self.validate_hostname = HostnameValidation(
require_tld=require_tld, allow_ip=True
Expand Down
12 changes: 11 additions & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ def test_equal_to_raises(
u"http://foobar.dk/",
u"http://foo-bar.dk/",
u"http://foo_bar.dk/",
u"http://foobar.dk?query=param",
u"http://foobar.dk/path?query=param",
u"http://foobar.dk/path?query=param&foo=faa",
u"http://foobar.museum/foobar",
u"http://192.168.0.1/foobar",
u"http://192.168.0.1:9000/fake",
Expand All @@ -400,7 +403,14 @@ def test_valid_url_passes(url_val, dummy_form, dummy_field):
validator(dummy_form, dummy_field)


@pytest.mark.parametrize("url_val", [u"http://localhost/foobar", u"http://foobar"])
@pytest.mark.parametrize(
"url_val",
[
u"http://localhost/foobar",
u"http://foobar",
u"http://foobar?query=param&foo=faa",
],
)
def test_valid_url_notld_passes(url_val, dummy_form, dummy_field):
"""
Require TLD option se to false, correct URL should pass without raising
Expand Down

0 comments on commit 150f16e

Please sign in to comment.