Skip to content

Commit 37593c1

Browse files
Fast path returns for normalize_path cases (#3189)
Co-authored-by: Kar Petrosyan <[email protected]>
1 parent 88a81c5 commit 37593c1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

httpx/_urlparse.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,17 @@ def normalize_path(path: str) -> str:
392392
393393
normalize_path("/path/./to/somewhere/..") == "/path/to"
394394
"""
395-
# https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
395+
# Fast return when no '.' characters in the path.
396+
if "." not in path:
397+
return path
398+
396399
components = path.split("/")
400+
401+
# Fast return when no '.' or '..' components in the path.
402+
if "." not in components and ".." not in components:
403+
return path
404+
405+
# https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.4
397406
output: list[str] = []
398407
for component in components:
399408
if component == ".":

0 commit comments

Comments
 (0)