Skip to content

Commit

Permalink
fix: avoid uri shadowing
Browse files Browse the repository at this point in the history
URIorCURIE validation function is wrongly identifying as CURIEs certain
URIs. This patch first tries to validate if a URIorCURIE is a valid URI,
otherwise it tries to validate if it's a valid CURIE.

Signed-off-by: Silvano Cirujano Cuesta <[email protected]>
  • Loading branch information
Silvanoc committed Oct 6, 2023
1 parent 91b7baa commit 35c3bc5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
16 changes: 12 additions & 4 deletions linkml_runtime/utils/metamodelcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from urllib.parse import urlparse

from rdflib import Literal, BNode, URIRef
import uritools
from rdflib.namespace import is_ncname
from rdflib.term import Identifier as rdflib_Identifier

Expand Down Expand Up @@ -105,10 +106,12 @@ def is_valid(cls, v: Union[str, URIRef, "Curie", "URIorCURIE"]) -> bool:
if not isinstance(v, (str, URIRef, Curie, URIorCURIE)):
return False
v = str(v)
if ':' in v and '://' not in v:
return URIorCURIE.is_curie(v)
if uritools.urisplit(v).isuri():
return True
elif uritools.isrelpath(v):
return True
else:
return URI.is_valid(v)
return URIorCURIE.is_curie(v)

@staticmethod
def is_absolute(v: str) -> bool:
Expand Down Expand Up @@ -142,7 +145,12 @@ def __init__(self, v: str) -> None:

@classmethod
def is_valid(cls, v: str) -> bool:
return v is not None and not URIorCURIE.is_curie(v) and cls.uri_re.match(v)
if uritools.urisplit(v).isuri():
return True
elif uritools.isrelpath(v):
return True
else:
return False


class Curie(URIorCURIE):
Expand Down
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ requests = "*"
prefixmaps = ">=0.1.4"
curies = ">=0.5.4"
pydantic = ">=1.10.2, <3.0.0"
uritools = "^4.0.2"

[tool.poetry.dev-dependencies]
coverage = "^6.2"
Expand Down

0 comments on commit 35c3bc5

Please sign in to comment.