>> from_n3(sample) Traceback (most recent call last): Fi...">

Trailing backslash in literal causes from_n3 to throw exception · Issue #546 · RDFLib/rdflib (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@scossu

Description

@scossu

Steps to reproduce (Python 3.4):

>>> from rdflib.util import from_n3
>>> sample = "\"Sample string with trailing backslash\\\"^^xsd:string"
>>> from_n3(sample)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/rdflib/util.py", line 183, in from_n3
    value = value.encode("raw-unicode-escape").decode("unicode-escape")
UnicodeDecodeError: 'unicodeescape' codec can't decode byte 0x5c in position 37: \ at end of string

I am aware of the trailing backslash problem with raw strings: https://docs.python.org/2/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash

I would like to know whether this is a rdflib bug and, if not, how I should handle my string before passing it to from_n3.