Skip to content

Commit e261af3

Browse files
committed
Merge pull request #548 from joernhees/fix_from_n3_backslashreduction
fix double reduction of \ escapes in from_n3, fixes #546
2 parents fa4172c + 3670738 commit e261af3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

rdflib/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def from_n3(s, default=None, backend=None, nsm=None):
177177
if rest.startswith("@"):
178178
language = rest[1:] # strip leading at sign
179179

180-
value = value.replace(r'\"', '"').replace('\\\\', '\\')
180+
value = value.replace(r'\"', '"')
181181
# Hack: this should correctly handle strings with either native unicode
182182
# characters, or \u1234 unicode escapes.
183183
value = value.encode("raw-unicode-escape").decode("unicode-escape")

test/test_util.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def test_util_from_n3_expectliteralwithescapedquote(self):
223223
s = '"\\""'
224224
res = util.from_n3(s, default=None, backend=None)
225225
self.assert_(res, Literal('\\"', lang='en'))
226+
227+
def test_util_from_n3_expectliteralwithtrailingbackslash(self):
228+
s = '"trailing\\\\"^^<http://www.w3.org/2001/XMLSchema#string>'
229+
res = util.from_n3(s)
230+
self.assert_(res, Literal('trailing\\', datatype=XSD['string']))
231+
self.assert_(res.n3(), s)
226232

227233
def test_util_from_n3_expectpartialidempotencewithn3(self):
228234
for n3 in ('<http://ex.com/foo>',

0 commit comments

Comments
 (0)