Skip to content

Commit b39417f

Browse files
Enforce string paths in file path utility
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c915367 commit b39417f

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎hyperbrowser/client/file_utils.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def ensure_existing_file_path(
1818
"file_path must be a string or os.PathLike object",
1919
original_error=exc,
2020
) from exc
21+
if not isinstance(normalized_path, str):
22+
raise HyperbrowserError("file_path must resolve to a string path")
2123
if not os.path.exists(normalized_path):
2224
raise HyperbrowserError(missing_file_message)
2325
if not os.path.isfile(normalized_path):

‎tests/test_file_utils.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ def test_ensure_existing_file_path_rejects_invalid_path_type():
6161
missing_file_message="missing",
6262
not_file_message="not-file",
6363
)
64+
65+
66+
def test_ensure_existing_file_path_rejects_non_string_fspath_results():
67+
with pytest.raises(HyperbrowserError, match="file_path must resolve to a string"):
68+
ensure_existing_file_path(
69+
b"/tmp/bytes-path", # type: ignore[arg-type]
70+
missing_file_message="missing",
71+
not_file_message="not-file",
72+
)

0 commit comments

Comments
 (0)