rdfjs / N3.js

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

Triples containing Variable result in invalid turtle #383

Open mrkvon opened 3 months ago

mrkvon commented 3 months ago

When creating a triple with Variables in it, and then writing it as text/turtle, the outcome is invalid turtle.

const writer = new Writer({ format: 'text/turtle' })
writer.addQuad(new Quad(new Variable('a'), new NamedNode(foaf.knows), new Variable('c')))
writer.end((err, result) => {
  console.log(result)
})

This yields

?a <http://xmlns.com/foaf/0.1/knows> ?c.

which is invalid turtle.

Along the argumentation in #165, this could rather throw error or gracefully drop the triples containing Variable.

RubenVerborgh commented 3 months ago

Working as intended (writer always expects valid input), but we can indeed accept a PR along the lines of #165 to perform optional input sanitization.

mrkvon commented 3 months ago

Indeed relevant only if a feature like https://github.com/rdfjs/N3.js/pull/339#issuecomment-1482645969 is included.

bergos commented 3 months ago

May I throw in one of my recent blog posts RDF/JS for Data Processing. Summary of the blog post: Validation is a spectrum, and what is valid RDF depends on the context. That's why I like a modular approach, and rdf-validation could be one building block. Nevertheless, if a media type is given, it's legit that a serializer validates that the output is according to the spec. But I would recommend using flags, as mentioned in #339, to control the behavior, and ideally there is no performance impact.