You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that sparqlUpdateParser in src/patch-parser.js is partly relying on src/n3parser.js instead of conforming to SPARQL Query, in particular the prefix declaration. Also, PREFIX line ending with a dot (.) is not valid syntax in SPARQL Query AFAICT:
which essentially checks to see if there is "@" before prefix. Since the valid syntax "PREFIX" does not, it all falls apart.
So I don't know if there is a quick fix here but as far as conformance goes PrefixDecl is defined in SPARQL Query. I do not know if rdflib.js has a SPARQL Query parser somewhere or can borrow from somewhere.
I was going to PR something but think that what I wrote here should be reviewed. I don't have the bandwidth to dig deeper or find a clever solution because there is some legacy code and it can use more eyes.
So, an alterative way of fixing this issue is potentially updating or changing the N3 Parser which may or may not be supporting SPARQL directives, if all things generally remain the same, i.e., patch-parser could use an N3 parser's prefix declarations (for both @prefix and PREFIX).
This whole thing causes an issue in code depending on it like, e.g., NSS. So, AFAICT, NSS does not conform in that it rejects requests with valid payload containing PREFIX, and also accepts invalid syntax @prefix.
The text was updated successfully, but these errors were encountered:
csarven
changed the title
Use SPARQL Query prefix declaration instead of
Use SPARQL Query prefix declaration instead of relying on an N3 parser without sparqlPrefix implementation
Jun 10, 2024
It seems that
sparqlUpdateParser
insrc/patch-parser.js
is partly relying onsrc/n3parser.js
instead of conforming to SPARQL Query, in particular the prefix declaration. Also,PREFIX
line ending with a dot (.
) is not valid syntax in SPARQL Query AFAICT:The syntax of the prefix declaration in SPARQL 1.1 Query Language is as follows ( https://www.w3.org/TR/sparql11-query/#rPrefixDecl ):
And SPARQL Update states ( https://www.w3.org/TR/sparql11-update/#languageForm ):
SPARQL 1.2 Query language ( https://w3c.github.io/sparql-query/spec/#rPrefixDecl ) uses the same declaration as SPARQL 1.1 Query Language.
The following code causes two issues: 1) finds
@prefix
valid when it should be invalid, and 2) findsPREFIX
invalid when it should be valid:rdflib.js/src/patch-parser.js
Lines 76 to 91 in cfc0f8c
I think instead of
@prefix
, it should bePREFIX
(and adjust the length):if (!found && str.slice(j, j + 6) === 'PREFIX') {
and the prefix declaration line does not end with a dot (
.
) so perhaps the following is unnecessary:i = p.checkDot(str, i);
That's close to getting it working but the following line:
i = p.directive(str, j);
depends on n3parser. See:
And going further down the rabbit-hole we have this in token checker in n3parser:
rdflib.js/src/n3parser.js
Line 450 in cfc0f8c
which essentially checks to see if there is "@" before prefix. Since the valid syntax "PREFIX" does not, it all falls apart.
So I don't know if there is a quick fix here but as far as conformance goes
PrefixDecl
is defined in SPARQL Query. I do not know if rdflib.js has a SPARQL Query parser somewhere or can borrow from somewhere.Perhaps
src/sparql-to-query
is of help? See https://github.com/linkeddata/rdflib.js/blob/main/src/sparql-to-query.js#L267-L285I was going to PR something but think that what I wrote here should be reviewed. I don't have the bandwidth to dig deeper or find a clever solution because there is some legacy code and it can use more eyes.
sparqlPrefix
(in the issue title) implementation is in reference to current work on Notation 3 Language where it defines https://w3c.github.io/N3/spec/#grammar-production-sparqlPrefix :[1] n3Doc ::= ( ( n3Statement ".") | sparqlDirective) *
[4] sparqlDirective ::= sparqlBase | sparqlPrefix
[6] sparqlPrefix ::= PREFIX PNAME_NS IRIREF
So, an alterative way of fixing this issue is potentially updating or changing the N3 Parser which may or may not be supporting SPARQL directives, if all things generally remain the same, i.e., patch-parser could use an N3 parser's prefix declarations (for both
@prefix
andPREFIX
).This whole thing causes an issue in code depending on it like, e.g., NSS. So, AFAICT, NSS does not conform in that it rejects requests with valid payload containing
PREFIX
, and also accepts invalid syntax@prefix
.The text was updated successfully, but these errors were encountered: