Skip to content

Commit 4422f03

Browse files
committed
fix: url validator considers urls with /#/ as valid
1 parent ee088fa commit 4422f03

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/validators/url.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""URL."""
22

33
# standard
4-
from functools import lru_cache
54
import re
5+
from functools import lru_cache
66
from urllib.parse import unquote, urlsplit
77

88
# local
@@ -116,6 +116,7 @@ def _validate_optionals(path: str, query: str, fragment: str):
116116
if query:
117117
optional_segments &= bool(_query_regex().match(query))
118118
if fragment:
119+
fragment = fragment.lstrip("/") if fragment.startswith("/") else fragment
119120
optional_segments &= all(char_to_avoid not in fragment for char_to_avoid in ("/", "?"))
120121
return optional_segments
121122

tests/test_url.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"https://travel-usa.com/wisconsin/旅行/",
8585
"http://:::::::::::::@exmp.com",
8686
"http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
87+
"https://exchange.jetswap.finance/#/swap",
8788
# when simple_host=True
8889
# "http://localhost",
8990
# "http://localhost:8000",

0 commit comments

Comments
 (0)