rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
676 stars 127 forks source link

Incorrect parsing of a list containing a Notation3 graph term #357

Open phochste opened 1 year ago

phochste commented 1 year ago

The current 1.16.4 N3 parser doesn't handle lists containing Notation3 graph terms well:

This Notation3 document:

@prefix : <urn:example:> .

:s a ({ :a :b :c}) .

is parsed as:

Quad {
  id: '',
  _subject: NamedNode { id: 'urn:example:a' },
  _predicate: NamedNode { id: 'urn:example:b' },
  _object: NamedNode { id: 'urn:example:c' },
  _graph: BlankNode { id: '_:n3-0' }
}
Quad {
  id: '',
  _subject: NamedNode { id: 'urn:example:s' },
  _predicate: NamedNode { id: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' },
  _object: NamedNode { id: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil' },
  _graph: DefaultGraph { id: '' }
}
phochste commented 1 year ago

One of the problems is that starting a new formula escapes the correct initialization of the list at this line https://github.com/rdfjs/N3.js/blob/main/src/N3Parser.js#L475 and thus never sees the lines 481 to 509 which are required for this initialization.

One other problem is that I don't see any logic to turn the blank node of the graph term into a list item.