Skip to content

Commit b6073cc

Browse files
Require string type for env header JSON input
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 6fcb78d commit b6073cc

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

hyperbrowser/header_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def normalize_headers(
3939

4040

4141
def parse_headers_env_json(raw_headers: Optional[str]) -> Optional[Dict[str, str]]:
42-
if raw_headers is None or not raw_headers.strip():
42+
if raw_headers is None:
43+
return None
44+
if not isinstance(raw_headers, str):
45+
raise HyperbrowserError("HYPERBROWSER_HEADERS must be a string")
46+
if not raw_headers.strip():
4347
return None
4448
try:
4549
parsed_headers = json.loads(raw_headers)

tests/test_header_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def test_parse_headers_env_json_ignores_blank_values():
3636
assert parse_headers_env_json(" ") is None
3737

3838

39+
def test_parse_headers_env_json_rejects_non_string_input():
40+
with pytest.raises(
41+
HyperbrowserError, match="HYPERBROWSER_HEADERS must be a string"
42+
):
43+
parse_headers_env_json(123) # type: ignore[arg-type]
44+
45+
3946
def test_parse_headers_env_json_rejects_invalid_json():
4047
with pytest.raises(
4148
HyperbrowserError, match="HYPERBROWSER_HEADERS must be valid JSON object"

0 commit comments

Comments
 (0)