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

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

Open RinkeHoekstra opened this issue 8 months ago • 2 comments

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 \".

RinkeHoekstra avatar Jun 06 '24 08:06 RinkeHoekstra