gjhiggins/rdflib — Issue #65: backslashes in a literal are doubled when converted to string
Author: gjhiggins
Created: 2011-10-19 01:09:57+00:00
State: open
Labels: Milestone-Release2.5

Originally filed by brondsem@gmail.com on 2009-06-11T21:21:58

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'