linkeddata / rdflib.js

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

N3Parser: support escape sequences in local names #557

Open Yucukof opened 2 years ago

Yucukof commented 2 years ago

According to RDF 1.1 Turtle specification, the grammar accepts local names as production node, for ex foaf:name

This local name can contain escape sequences: image which are enumerated as follows:

[172s] | PN_LOCAL_ESC | ::= | '\' ('_' \| '~' \| '.' \| '-' \| '!' \| ' \| '&' \| "'" \| '(' \| ')' \| '*' \| '+' \| ',' \| ';' \| '=' \| '/' \| '?' \| '#' \| '@' \| '%')

However, when trying to parse the following turtle with rdflib,

@prefix interop: <http://www.w3.org/ns/solid/interop#> .

@prefix alice: <https://alice.example/#> .
@prefix alice-work: <https://work.alice.example/> .
@prefix alice-personal: <https://personal.alice.example/> .

alice:registries
  a interop:RegistrySet;
  interop:hasAgentRegistry alice:agents ;
  interop:hasAuthorizationRegistry alice:authorization ;
  interop:hasDataRegistry
    alice-work:data\/ ,
    alice-personal:data\/ .

Source: Solid Data Interoperability Panel

The following error is returned:

Error: Fetcher: Error trying to parse <file:///home/hba/Documents/Git/SOLID/files/data/registries.ttl> as Notation3:
SyntaxError: Line 25 of <file:///home/hba/Documents/Git/SOLID/files/data/registries.ttl>: Bad syntax: expected '.' or '}' or ']' at end of statement
at: "\/ ,
    alice-personal:data\/"

    at Fetcher.failFetch (/home/hba/Documents/Git/SOLID/src/node_modules/shex-methods/node_modules/rdflib/lib/fetcher.js:1100:17)
    at N3Handler.parse (/home/hba/Documents/Git/SOLID/src/node_modules/shex-methods/node_modules/rdflib/lib/fetcher.js:549:24)
    at /home/hba/Documents/Git/SOLID/src/node_modules/shex-methods/node_modules/rdflib/lib/fetcher.js:1890:24

I tracked the issue in the N3 parser in the following location. It is because the method breaks out of the loop when it finds the notNameChar \ instead of considering an escape sequence.

The following code change may be worth further investigation, as I am not sure what side-effect this may have.

Yucukof commented 2 years ago

(This certainly relates to #523)