Skip to content

Commit

Permalink
fix: URL fragment check (#305)
Browse files Browse the repository at this point in the history
- Fix erroneously forbidden characters in fragment check
- Narrow allowed characters for fragment based on standard
  • Loading branch information
darkdragon-001 authored Oct 5, 2023
1 parent b313f15 commit 15984e8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/validators/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def _validate_optionals(path: str, query: str, fragment: str, strict_query: bool
if query and parse_qs(query, strict_parsing=strict_query):
optional_segments &= True
if fragment:
fragment = fragment.lstrip("/") if fragment.startswith("/") else fragment
optional_segments &= all(char_to_avoid not in fragment for char_to_avoid in ("?",))
# See RFC3986 Section 3.5 Fragment for allowed characters
optional_segments &= bool(re.fullmatch(r"[0-9a-zA-Z?/:@\-._~!$&'()*+,;=]*", fragment))
return optional_segments


Expand Down
2 changes: 2 additions & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
"http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com",
"https://exchange.jetswap.finance/#/swap",
"https://www.foo.com/bar#/baz/test",
"https://matrix.to/#/!BSqRHgvCtIsGittkBG:talk.puri.sm/$1551464398"
+ "853539kMJNP:matrix.org?via=talk.puri.sm&via=matrix.org&via=disroot.org",
# when simple_host=True
# "http://localhost",
# "http://localhost:8000",
Expand Down

0 comments on commit 15984e8

Please sign in to comment.