rdflib.js icon indicating copy to clipboard operation
rdflib.js copied to clipboard

Fix for `BlankNode` as `NamedNode` when parsing JSON-LD #555

Open RinkeHoekstra opened this issue 2 years ago • 1 comments

The JSON-LD parser currently uses the JSON-LD flattening algorithm of jsonld.js. This algorithm assigns @id attributes to blank nodes, but the JSON-LD parser only creates a BlankNode when no @id is present.

This means that currently, the blank nodes in JSON-LD are interpreted as NamedNode, which is incorrect.

This pull request does the following:

  • Add a check to see whether the @id value starts with _:.
  • If it does, it is a BlankNode, otherwise it is a NamedNode.
  • If it is a blank node, strip it from the _: as this will be added by the instantiation of the BlankNode class.
  • Make sure to perform this check whenever a new object node is created (there were three separate checks in the code)

This fixes #555

Also raised an issue in rdf-canonize (https://github.com/digitalbazaar/rdf-canonize/issues/45) to flag the problem that blank node identifiers generated by jsonld.js are not unique across loads (this is the cause of issue #405 )

RinkeHoekstra avatar Jul 19 '22 07:07 RinkeHoekstra

@RinkeHoekstra CI fails. If I only add your first commit https://github.com/linkeddata/rdflib.js/pull/558/commits/e0d332e0cb53207bbb0879626b6dc1f19e4b1b3f it does not fail locally

I think you should only keep this one and make other PR for your last 2 commits that are not directly related so I can merge your PR.

bourgeoa avatar Aug 23 '22 19:08 bourgeoa

resolved with https://github.com/linkeddata/rdflib.js/pull/589/commits/17052b62209a92112d21a01dd8d2cd2f5fde16a3

bourgeoa avatar Jan 26 '23 18:01 bourgeoa