Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add path_safe method #1150

Merged
merged 15 commits into from
Sep 23, 2024
14 changes: 13 additions & 1 deletion yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ class URL:
_FRAGMENT_REQUOTER = _Quoter(safe="?/:@")

_UNQUOTER = _Unquoter()
_PATH_UNQUOTER = _Unquoter(ignore="/", unsafe="+")
_PATH_UNQUOTER = _Unquoter(unsafe="+")
bdraco marked this conversation as resolved.
Show resolved Hide resolved
_SAFE_PATH_UNQUOTER = _Unquoter(ignore="/%", unsafe="+")
bdraco marked this conversation as resolved.
Show resolved Hide resolved
_QS_UNQUOTER = _Unquoter(qs=True)

_val: SplitResult
Expand Down Expand Up @@ -710,6 +711,17 @@ def path(self) -> str:
"""
return self._PATH_UNQUOTER(self.raw_path)

@cached_property
def safe_path(self) -> str:
bdraco marked this conversation as resolved.
Show resolved Hide resolved
"""Decoded path of URL.

/ for absolute URLs without path part.

/ (%2F) and % (%25) are not decoded

"""
return self._SAFE_PATH_UNQUOTER(self.raw_path)

@cached_property
def _parsed_query(self) -> List[Tuple[str, str]]:
"""Parse query part of URL."""
Expand Down
Loading