Skip to content

Commit e0c27d2

Browse files
committed
make is_bubble_uid return False for non-string inputs
1 parent 89233e2 commit e0c27d2

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/bubble_data_api_client/validation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import re
44
from collections.abc import Iterable
5+
from typing import Any
56

67
_BUBBLE_UID_PATTERN: re.Pattern[str] = re.compile(r"^[0-9]+x[0-9]+$")
78

89

9-
def is_bubble_uid(value: str) -> bool:
10+
def is_bubble_uid(value: Any) -> bool:
1011
"""Check if a string matches the Bubble UID format (e.g., '1767090310181x452059685440531200')."""
12+
if not isinstance(value, str):
13+
return False
1114
return _BUBBLE_UID_PATTERN.fullmatch(value) is not None
1215

1316

src/tests/unit/test_validation.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ def test_is_bubble_uid_valid(value: str) -> None:
1919
assert is_bubble_uid(value) is True
2020

2121

22+
@pytest.mark.parametrize(
23+
("value", "reason"),
24+
[
25+
(None, "None"),
26+
(123, "integer"),
27+
(123.456, "float"),
28+
(["1x2"], "list"),
29+
({"uid": "1x2"}, "dict"),
30+
(True, "boolean"),
31+
],
32+
)
33+
def test_is_bubble_uid_non_string(value: object, reason: str) -> None:
34+
"""Non-string values should return False without raising."""
35+
assert is_bubble_uid(value) is False, f"should reject: {reason}"
36+
37+
2238
@pytest.mark.parametrize(
2339
("value", "reason"),
2440
[

0 commit comments

Comments
 (0)