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

N3Parser: support escape sequences in local names #557

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Yucukof
Copy link

@Yucukof Yucukof commented Jun 8, 2022

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

Yucukof commented Jul 19, 2022

(This certainly relates to #523)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

None yet

2 participants