pyld
pyld copied to clipboard
to_rdf silently ignores invalid IRIs
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 ....
https://github.com/digitalbazaar/pyld/blob/316fbc2c9e25b3cf718b4ee189012a64b91f17e7/lib/pyld/jsonld.py#L3547-L3552