Skip to content

Commit 3474b7e

Browse files
Reject backslashes in normalized base URLs
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 550d30a commit 3474b7e

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎hyperbrowser/config.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def normalize_base_url(base_url: str) -> str:
3838
raise HyperbrowserError("base_url must not contain newline characters")
3939
if any(character.isspace() for character in normalized_base_url):
4040
raise HyperbrowserError("base_url must not contain whitespace characters")
41+
if "\\" in normalized_base_url:
42+
raise HyperbrowserError("base_url must not contain backslashes")
4143

4244
parsed_base_url = urlparse(normalized_base_url)
4345
if (

‎tests/test_config.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ def test_client_config_rejects_empty_or_invalid_base_url():
218218
HyperbrowserError, match="base_url must not contain whitespace characters"
219219
):
220220
ClientConfig(api_key="test-key", base_url="https://example .local")
221+
with pytest.raises(
222+
HyperbrowserError, match="base_url must not contain backslashes"
223+
):
224+
ClientConfig(api_key="test-key", base_url="https://example.local\\api")
221225

222226

223227
def test_client_config_normalizes_headers_to_internal_copy():
@@ -333,3 +337,7 @@ def test_client_config_normalize_base_url_validates_and_normalizes():
333337
HyperbrowserError, match="base_url must not contain whitespace characters"
334338
):
335339
ClientConfig.normalize_base_url("https://example.local/\tapi")
340+
with pytest.raises(
341+
HyperbrowserError, match="base_url must not contain backslashes"
342+
):
343+
ClientConfig.normalize_base_url("https://example.local\\api")

‎tests/test_url_building.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ def test_client_build_url_rejects_runtime_invalid_base_url_changes():
110110
):
111111
client._build_url("/session")
112112

113+
client.config.base_url = "https://example.local\\api"
114+
with pytest.raises(
115+
HyperbrowserError, match="base_url must not contain backslashes"
116+
):
117+
client._build_url("/session")
118+
113119
client.config.base_url = " "
114120
with pytest.raises(HyperbrowserError, match="base_url must not be empty"):
115121
client._build_url("/session")

0 commit comments

Comments
 (0)