From: Tom Christie Date: Fri, 17 May 2024 17:25:38 +0000 (+0100) Subject: Fast path returns for normalize_path cases (#3189) X-Git-Tag: 0.27.1~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=37593c1952f4972040f6163da67e3777fd3d2e94;p=thirdparty%2Fhttpx.git Fast path returns for normalize_path cases (#3189) Co-authored-by: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com> --- diff --git a/httpx/_urlparse.py b/httpx/_urlparse.py index 883f0895..575e6d56 100644 --- a/httpx/_urlparse.py +++ b/httpx/_urlparse.py @@ -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 == ".":