RDFLib/rdflib — Issue #64: backslashes in a literal are doubled when converted to string
Author: gjhiggins
Created: 2012-02-20 08:31:47+00:00
State: open

brondsem@gmail.com, 2009-06-11T21:21:58.000Z

Given a.xml as:

a\b

Then this python exemplifies the bug. The indented lines are output/return
values. Only the last line 3 lines work as expected. All others have
double-escaped slashes.

from rdflib.Graph import Graph
g = Graph()
g.load('a.xml')
lit = list(g.objects())[0]
lit
rdflib.Literal('a\\b', language=None, datatype=None)
str(lit)
'a\\\\b'
lit.n3()
u'"a\\\\b"'
lit.toPython()
rdflib.Literal('a\\b', language=None, datatype=None)

list(g.objects())[0] == 'a\\b'
True
list(g.objects())[0] == 'a\\\\b'
False
list(g.objects())[0][:]
u'a\\b'

Comment 1 by brondsem@gmail.com
Looks like the problem is in Literal's
def __str__(self):
return self.encode("unicode-escape")

Not sure what the right way to encode is, though.

Comment 2 by eik...@gmail.com

Comment 3 by eik...@gmail.com

Comment 4 by eik...@gmail.com
Added a test case in r1754. This does not appear to be an issue in trunk.

Comment 5 by eik...@gmail.com
This issue was updated by revision 3cfb0bd008fd.