Skip to content

Commit

Permalink
fix: url validator considers urls with /#/ as valid
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienthiery committed Aug 17, 2023
1 parent ee088fa commit 4422f03
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/validators/url.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""URL."""

# standard
from functools import lru_cache
import re
from functools import lru_cache
from urllib.parse import unquote, urlsplit

# local
Expand Down Expand Up @@ -116,6 +116,7 @@ def _validate_optionals(path: str, query: str, fragment: str):
if query:
optional_segments &= bool(_query_regex().match(query))
if fragment:
fragment = fragment.lstrip("/") if fragment.startswith("/") else fragment
optional_segments &= all(char_to_avoid not in fragment for char_to_avoid in ("/", "?"))
return optional_segments

Expand Down
1 change: 1 addition & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"https://travel-usa.com/wisconsin/旅行/",
"http://:::::::::::::@exmp.com",
"http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
"https://exchange.jetswap.finance/#/swap",
# when simple_host=True
# "http://localhost",
# "http://localhost:8000",
Expand Down

0 comments on commit 4422f03

Please sign in to comment.