Skip to content

Commit

Permalink
Add additional typecheck to curie validation (#542)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
matentzn authored Jun 24, 2024
1 parent fcb79b7 commit edf432a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,18 @@ def get_dict_from_mapping(map_obj: Union[Any, Dict[Any, Any], SSSOM_Mapping]) ->

def _is_curie(string: str) -> bool:
"""Check if the string is a CURIE."""
return bool(CURIE_RE.match(string))
if string and isinstance(string, str):
return bool(CURIE_RE.match(string))
else:
return False


def _is_iri(string: str) -> bool:
"""Check if the string is an IRI."""
return validators.url(string)
if string and isinstance(string, str):
return validators.url(string)
else:
return False


def get_prefix_from_curie(curie: str) -> str:
Expand Down

0 comments on commit edf432a

Please sign in to comment.