Skip to content

Commit 9d6b513

Browse files
Reject whitespace characters in API path components
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 86049e7 commit 9d6b513

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

hyperbrowser/client/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def _build_url(self, path: str) -> str:
100100
raise HyperbrowserError("path must not contain backslashes")
101101
if "\n" in decoded_path or "\r" in decoded_path:
102102
raise HyperbrowserError("path must not contain newline characters")
103+
if any(character.isspace() for character in decoded_path):
104+
raise HyperbrowserError("path must not contain whitespace characters")
103105
normalized_segments = [
104106
segment for segment in decoded_path.split("/") if segment
105107
]

tests/test_url_building.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
136136
HyperbrowserError, match="path must not contain newline characters"
137137
):
138138
client._build_url("/session\nnext")
139+
with pytest.raises(
140+
HyperbrowserError, match="path must not contain whitespace characters"
141+
):
142+
client._build_url("/session name")
139143
with pytest.raises(HyperbrowserError, match="path must be a relative API path"):
140144
client._build_url("https://api.hyperbrowser.ai/session")
141145
with pytest.raises(HyperbrowserError, match="path must be a relative API path"):
@@ -182,6 +186,14 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
182186
HyperbrowserError, match="path must not contain newline characters"
183187
):
184188
client._build_url("/api/%250Asegment")
189+
with pytest.raises(
190+
HyperbrowserError, match="path must not contain whitespace characters"
191+
):
192+
client._build_url("/api/%20segment")
193+
with pytest.raises(
194+
HyperbrowserError, match="path must not contain whitespace characters"
195+
):
196+
client._build_url("/api/%09segment")
185197
finally:
186198
client.close()
187199

0 commit comments

Comments
 (0)