File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,14 @@ def __init__(
5555 self .transport = transport (config .api_key , headers = config .headers )
5656
5757 def _build_url (self , path : str ) -> str :
58- normalized_path = path if path .startswith ("/" ) else f"/{ path } "
58+ if not isinstance (path , str ):
59+ raise HyperbrowserError ("path must be a string" )
60+ stripped_path = path .strip ()
61+ if not stripped_path :
62+ raise HyperbrowserError ("path must not be empty" )
63+ normalized_path = (
64+ stripped_path if stripped_path .startswith ("/" ) else f"/{ stripped_path } "
65+ )
5966 if normalized_path == "/api" or normalized_path .startswith ("/api/" ):
6067 return f"{ self .config .base_url } { normalized_path } "
6168 return f"{ self .config .base_url } /api{ normalized_path } "
Original file line number Diff line number Diff line change 1+ import pytest
2+
13from hyperbrowser import Hyperbrowser
24from hyperbrowser .config import ClientConfig
5+ from hyperbrowser .exceptions import HyperbrowserError
36
47
58def test_client_build_url_normalizes_leading_slash ():
@@ -29,3 +32,14 @@ def test_client_build_url_uses_normalized_base_url():
2932 assert client ._build_url ("/session" ) == "https://example.local/api/session"
3033 finally :
3134 client .close ()
35+
36+
37+ def test_client_build_url_rejects_empty_or_non_string_paths ():
38+ client = Hyperbrowser (config = ClientConfig (api_key = "test-key" ))
39+ try :
40+ with pytest .raises (HyperbrowserError , match = "path must not be empty" ):
41+ client ._build_url (" " )
42+ with pytest .raises (HyperbrowserError , match = "path must be a string" ):
43+ client ._build_url (123 ) # type: ignore[arg-type]
44+ finally :
45+ client .close ()
You can’t perform that action at this time.
0 commit comments