N3 parse error on single quote within single quotes · Issue #732 · RDFLib/rdflib (original) (raw)
Escaping an interior single quote within a single quoted string:
from rdflib import Graph
rdf = """PREFIX ex: http://a.example ex:test ex:pattern ' \'' . """ Graph().parse(data=rdf, format="turtle")
produces the following error:
File "/Users/mrf7578/Development/venv/parsers/lib/python3.6/site-packages/rdflib/plugins/parsers/notation3.py", line 1591, in strconst
"bad escape")
File "/Users/mrf7578/Development/venv/parsers/lib/python3.6/site-packages/rdflib/plugins/parsers/notation3.py", line 1615, in BadSyntax
raise BadSyntax(self._thisDoc, self.lines, argstr, i, msg)
rdflib.plugins.parsers.notation3.BadSyntax: at line 2 of <>:
Bad syntax (bad escape) at ^ in:
"b"PREFIX ex: <http://a.example>\nex:test ex:pattern ' "^b"\\'' .\n""
Changing lines 1578 and 1580 in notation3.py (rdflib 4.2.2) and adding a "\'" on the end of the pattern strings - current:
1588 k = 'abfrtvn\"'.find(ch) 1589 if k >= 0: 1590 uch = '\a\b\f\r\t\v\n\"'[k]
new:
k = 'abfrtvn\\"\''.find(ch)
if k >= 0:
uch = '\a\b\f\r\t\v\n\\"\''[k]
Fixes this problem