Skip to content

Commit edf432a

Browse files
authored
Add additional typecheck to curie validation (#542)
Due to the lack of type safety, i can pass a non string to the `_is_curie` method, which causes the method to fail hard when its trying to do regex matching. Here, i add an additional safety net around the matching processing, making sure the value is not None, and is indeed a string (and not a number or some other kind of non-string).
1 parent fcb79b7 commit edf432a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/sssom/util.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,12 +1107,18 @@ def get_dict_from_mapping(map_obj: Union[Any, Dict[Any, Any], SSSOM_Mapping]) ->
11071107

11081108
def _is_curie(string: str) -> bool:
11091109
"""Check if the string is a CURIE."""
1110-
return bool(CURIE_RE.match(string))
1110+
if string and isinstance(string, str):
1111+
return bool(CURIE_RE.match(string))
1112+
else:
1113+
return False
11111114

11121115

11131116
def _is_iri(string: str) -> bool:
11141117
"""Check if the string is an IRI."""
1115-
return validators.url(string)
1118+
if string and isinstance(string, str):
1119+
return validators.url(string)
1120+
else:
1121+
return False
11161122

11171123

11181124
def get_prefix_from_curie(curie: str) -> str:

0 commit comments

Comments
 (0)