Skip to content

Commit 24e438b

Browse files
Reject leading or trailing whitespace in operation names
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 9f941a7 commit 24e438b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

hyperbrowser/client/polling.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def _validate_operation_name(operation_name: str) -> None:
3131
raise HyperbrowserError("operation_name must be a string")
3232
if not operation_name.strip():
3333
raise HyperbrowserError("operation_name must not be empty")
34+
if operation_name != operation_name.strip():
35+
raise HyperbrowserError(
36+
"operation_name must not contain leading or trailing whitespace"
37+
)
3438
if any(
3539
ord(character) < 32 or ord(character) == 127 for character in operation_name
3640
):

tests/test_polling.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,17 @@ def test_polling_helpers_validate_retry_and_interval_configuration():
659659
retry_delay_seconds=0,
660660
)
661661

662+
with pytest.raises(
663+
HyperbrowserError,
664+
match="operation_name must not contain leading or trailing whitespace",
665+
):
666+
retry_operation(
667+
operation_name=" invalid-retry ",
668+
operation=lambda: "ok",
669+
max_attempts=1,
670+
retry_delay_seconds=0,
671+
)
672+
662673
with pytest.raises(HyperbrowserError, match="operation_name must be a string"):
663674
retry_operation(
664675
operation_name=123, # type: ignore[arg-type]
@@ -814,6 +825,17 @@ async def validate_async_operation_name() -> None:
814825
poll_interval_seconds=0.1,
815826
max_wait_seconds=1.0,
816827
)
828+
with pytest.raises(
829+
HyperbrowserError,
830+
match="operation_name must not contain leading or trailing whitespace",
831+
):
832+
await poll_until_terminal_status_async(
833+
operation_name=" invalid-async ",
834+
get_status=lambda: asyncio.sleep(0, result="completed"),
835+
is_terminal_status=lambda value: value == "completed",
836+
poll_interval_seconds=0.1,
837+
max_wait_seconds=1.0,
838+
)
817839
with pytest.raises(
818840
HyperbrowserError,
819841
match="operation_name must not contain control characters",

0 commit comments

Comments
 (0)