Skip to content

Commit 6483ca8

Browse files
Normalize extra leading slashes in URL path builder
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 6280640 commit 6483ca8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

hyperbrowser/client/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def _build_url(self, path: str) -> str:
7171
stripped_path = path.strip()
7272
if not stripped_path:
7373
raise HyperbrowserError("path must not be empty")
74-
normalized_path = (
75-
stripped_path if stripped_path.startswith("/") else f"/{stripped_path}"
76-
)
74+
normalized_path = f"/{stripped_path.lstrip('/')}"
7775
if normalized_path == "/api" or normalized_path.startswith("/api/"):
7876
return f"{self.config.base_url}{normalized_path}"
7977
return f"{self.config.base_url}/api{normalized_path}"

tests/test_url_building.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ def test_client_build_url_normalizes_leading_slash():
2020
client._build_url("api/session")
2121
== "https://api.hyperbrowser.ai/api/session"
2222
)
23+
assert (
24+
client._build_url("//api/session")
25+
== "https://api.hyperbrowser.ai/api/session"
26+
)
27+
assert (
28+
client._build_url("///session") == "https://api.hyperbrowser.ai/api/session"
29+
)
2330
finally:
2431
client.close()
2532

0 commit comments

Comments
 (0)