Skip to content

Commit

Permalink
Fast path returns for normalize_path cases (#3189)
Browse files Browse the repository at this point in the history
Co-authored-by: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com>
  • Loading branch information
tomchristie and karpetrosyan committed May 17, 2024
1 parent 88a81c5 commit 37593c1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion httpx/_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,17 @@ def normalize_path(path: str) -> str:
normalize_path("/path/./to/somewhere/..") == "/path/to"
"""
# https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
# Fast return when no '.' characters in the path.
if "." not in path:
return path

components = path.split("/")

# Fast return when no '.' or '..' components in the path.
if "." not in components and ".." not in components:
return path

# https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
output: list[str] = []
for component in components:
if component == ".":
Expand Down

0 comments on commit 37593c1

Please sign in to comment.