walidazizi / rdflib

Automatically exported from code.google.com/p/rdflib
Other
0 stars 0 forks source link

backslashes in a literal are doubled when converted to string #66

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Given a.xml as:
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foo="http://foo/">
    <foo:bar>a\b</foo:bar>  
</rdf:RDF>

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'

Original issue reported on code.google.com by brondsem@gmail.com on 11 Jun 2009 at 9:21

GoogleCodeExporter commented 8 years ago
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.

Original comment by brondsem@gmail.com on 11 Jun 2009 at 9:34

GoogleCodeExporter commented 8 years ago

Original comment by eik...@gmail.com on 1 Feb 2010 at 8:16

GoogleCodeExporter commented 8 years ago

Original comment by eik...@gmail.com on 1 Feb 2010 at 8:54

GoogleCodeExporter commented 8 years ago
Added a test case in r1754. This does not appear to be an issue in trunk.

Original comment by eik...@gmail.com on 2 Feb 2010 at 9:38

GoogleCodeExporter commented 8 years ago
This issue was updated by revision 3cfb0bd008fd.

Original comment by eik...@gmail.com on 30 Mar 2011 at 9:06