Skip to content

Commit 65f1f71

Browse files
committed
Make _is_valid_absolute_iri also count hash chars.
1 parent d981093 commit 65f1f71

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

lib/pyld/jsonld.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6578,7 +6578,8 @@ def _is_valid_absolute_iri(v):
65786578
65796579
:return: True if the value is a valid absolute IRI, False if not.
65806580
"""
6581-
return _is_absolute_iri(v) and _is_valid_uri(v)
6581+
# TODO: _is_valid_uri is flawed, so maybe replace it with something better
6582+
return _is_absolute_iri(v) and v.count('#') <= 1 and _is_valid_uri(v)
65826583

65836584

65846585
def _is_relative_iri(v):

tests/runtests.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,9 +1017,6 @@ def write(self, filename):
10171017
# blank node property
10181018
'.*toRdf-manifest#te075$',
10191019
'.*toRdf-manifest#te122$',
1020-
# rel vocab
1021-
'.*toRdf-manifest#te111$',
1022-
'.*toRdf-manifest#te112$',
10231020
]
10241021
},
10251022
'skip': {

tests/test_jsonld.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,33 @@ def test_format_takes_precedence_over_legacy_mode(self):
10001000
"^^<http://www.w3.org/2001/XMLSchema#double> .\n\n"
10011001
)
10021002

1003+
def test_to_rdf_skips_relative_vocab_property_that_expands_to_invalid_iri(self):
1004+
"""
1005+
to_rdf should omit property IRIs that expand to invalid RDF IRIs.
1006+
"""
1007+
input = {
1008+
"@context": [
1009+
{
1010+
"@version": 1.1,
1011+
"@base": "http://example.com/some/deep/directory/and/file/",
1012+
"@vocab": "http://example.com/vocabulary/",
1013+
},
1014+
{"@vocab": "./rel2#"},
1015+
],
1016+
"@id": "relativePropertyIris",
1017+
"link": "link",
1018+
"#fragment-works": "#fragment-works",
1019+
}
1020+
1021+
nquads = jsonld.to_rdf(input, options={'format': 'application/n-quads'})
1022+
1023+
assert (
1024+
'<http://example.com/some/deep/directory/and/file/relativePropertyIris> '
1025+
'<http://example.com/vocabulary/./rel2#link> '
1026+
'"link"^^<http://www.w3.org/2001/XMLSchema#string> .'
1027+
) in nquads
1028+
assert '##fragment-works' not in nquads
1029+
10031030
def test_large_integer_to_rdf_double_conversion_processing_mode(self):
10041031
"""
10051032
In json-ld-1.1 processing mode, large integers should be emitted as xsd:double,

0 commit comments

Comments
 (0)