digitalbazaar/pyld

to_rdf silently ignores invalid IRIs

aucampia opened this issue · 1 comments

When I run to_rdf on an object with an invalid @id:

import pyld.jsonld as jsonld
result = jsonld.to_rdf({"@id": "http://example.com/some id", "@type": "http://example.com/some_type"})

The the value of result will be

{'@default': []}

In contrast, if I fix the @id to be a valid URI

import pyld.jsonld as jsonld
result = jsonld.to_rdf({"@id": "http://example.com/some_id", "@type": "http://example.com/some_type"})

The the value of result will be

{'@default': [{'subject': {'type': 'IRI', 'value': 'http://example.com/some_id'}, 'predicate': {'type': 'IRI', 'value': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'}, 'object': {'type': 'IRI', 'value': 'http://example.com/some_type'}}]}

I expect that running to_rdf on JSON-LD with invalid IRIs error out instead of silently ignoring the invalid triples.

I think the right solution is to change continue here in _graph_to_rdf on line 3551 to raise ....

pyld/lib/pyld/jsonld.py

Lines 3547 to 3552 in 316fbc2

for item in items:
# skip relative IRI subjects and predicates
if not (_is_absolute_iri(id_) and
_is_absolute_iri(property)):
continue