Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RinkeHoekstra opened this issue Jun 6, 2024 · 2 comments · May be fixed by #652
Open

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

RinkeHoekstra opened this issue Jun 6, 2024 · 2 comments · May be fixed by #652

Comments

@RinkeHoekstra
Copy link
Contributor

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:

rdflib.js/src/serializer.js

Lines 584 to 589 in cfc0f8c

if (str.length > 20 && // Long enough to make sense
str.slice(-1) !== '"' && // corner case'
flags.indexOf('n') < 0 && // Force single line
(str.indexOf('\n') > 0 || str.indexOf('"') > 0)) {
delim = '"""'
forbidden = this.forbidden3

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
Copy link
Contributor

bourgeoa commented Jun 6, 2024

Thanks. Please propose a non regressive PR

RinkeHoekstra added a commit to RinkeHoekstra/rdflib.js that referenced this issue Jul 10, 2024
@RinkeHoekstra RinkeHoekstra linked a pull request Jul 10, 2024 that will close this issue
@RinkeHoekstra
Copy link
Contributor Author

Apologies for the delay, @bourgeoa I created a pull request #652. Turns out it was a very small fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants