Skip to content

Commit 56bc6d5

Browse files
Require concrete path inputs in URL builder
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent dc00da2 commit 56bc6d5

File tree

2 files changed

+4
-59
lines changed

2 files changed

+4
-59
lines changed

hyperbrowser/client/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _parse_url_components(
146146
)
147147

148148
def _build_url(self, path: str) -> str:
149-
if not isinstance(path, str):
149+
if type(path) is not str:
150150
raise HyperbrowserError("path must be a string")
151151
try:
152152
stripped_path = path.strip()

tests/test_url_building.py

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -353,69 +353,14 @@ def test_client_build_url_rejects_empty_or_non_string_paths():
353353
client.close()
354354

355355

356-
def test_client_build_url_wraps_path_strip_runtime_errors():
356+
def test_client_build_url_rejects_string_subclass_path_inputs():
357357
client = Hyperbrowser(config=ClientConfig(api_key="test-key"))
358358
try:
359359
class _BrokenPath(str):
360-
def strip(self, chars=None): # type: ignore[override]
361-
_ = chars
362-
raise RuntimeError("path strip exploded")
360+
pass
363361

364-
with pytest.raises(HyperbrowserError, match="Failed to normalize path") as exc_info:
365-
client._build_url(_BrokenPath("/session"))
366-
367-
assert isinstance(exc_info.value.original_error, RuntimeError)
368-
finally:
369-
client.close()
370-
371-
372-
def test_client_build_url_preserves_hyperbrowser_path_strip_errors():
373-
client = Hyperbrowser(config=ClientConfig(api_key="test-key"))
374-
try:
375-
class _BrokenPath(str):
376-
def strip(self, chars=None): # type: ignore[override]
377-
_ = chars
378-
raise HyperbrowserError("custom path strip failure")
379-
380-
with pytest.raises(HyperbrowserError, match="custom path strip failure") as exc_info:
381-
client._build_url(_BrokenPath("/session"))
382-
383-
assert exc_info.value.original_error is None
384-
finally:
385-
client.close()
386-
387-
388-
def test_client_build_url_wraps_non_string_path_strip_results():
389-
client = Hyperbrowser(config=ClientConfig(api_key="test-key"))
390-
try:
391-
class _BrokenPath(str):
392-
def strip(self, chars=None): # type: ignore[override]
393-
_ = chars
394-
return object()
395-
396-
with pytest.raises(HyperbrowserError, match="Failed to normalize path") as exc_info:
397-
client._build_url(_BrokenPath("/session"))
398-
399-
assert isinstance(exc_info.value.original_error, TypeError)
400-
finally:
401-
client.close()
402-
403-
404-
def test_client_build_url_wraps_string_subclass_path_strip_results():
405-
client = Hyperbrowser(config=ClientConfig(api_key="test-key"))
406-
try:
407-
class _BrokenPath(str):
408-
class _NormalizedPath(str):
409-
pass
410-
411-
def strip(self, chars=None): # type: ignore[override]
412-
_ = chars
413-
return self._NormalizedPath("/session")
414-
415-
with pytest.raises(HyperbrowserError, match="Failed to normalize path") as exc_info:
362+
with pytest.raises(HyperbrowserError, match="path must be a string"):
416363
client._build_url(_BrokenPath("/session"))
417-
418-
assert isinstance(exc_info.value.original_error, TypeError)
419364
finally:
420365
client.close()
421366

0 commit comments

Comments
 (0)