linkeddata / rdflib.js

Linked Data API for JavaScript
http://linkeddata.github.io/rdflib.js/doc/
Other
560 stars 142 forks source link

`stringToN3` uses invalid delimiter for literals that contain quotes or newlines. #650

Open RinkeHoekstra opened 1 month ago

RinkeHoekstra commented 1 month ago

The serializer to NQuads (and turtle and others) uses the stringToN3 function to convert the value of a string literal to a safe string in the output syntax.

However, the code uses the triple quote """ as delimiter for strings that contain a newline or a quote " character:

https://github.com/linkeddata/rdflib.js/blob/cfc0f8c437d7872d76dc384d686c28d5d6100e35/src/serializer.js#L584-L589

This is not a valid serialization for NQuads, see the literal production grammar:

https://www.w3.org/TR/n-quads/#grammar-production-literal

The stringToN3 function should use the normal escaping using a backslash, i.e. \n and \".

bourgeoa commented 4 weeks ago

Thanks. Please propose a non regressive PR