Prevent `from_n3` from unescaping `\xhh`
This is a fairly pragmatic fix to a problem which should be solved by
changing `from_n3` to do the same as the actual n3/turtle parser.
There are still many issues with this function, some of which I added
tests for.
@@ -137,7 +137,7 @@ def to_term(s, default=None):
raise Exception(msg)
-def from_n3(s, default=None, backend=None, nsm=None):
+def from_n3(s: str, default=None, backend=None, nsm=None):
r'''
Creates the Identifier corresponding to the given n3 string.
@@ -193,6 +193,9 @@ def from_n3(s, default=None, backend=None, nsm=None):
language = rest[1:] # strip leading at sign
value = value.replace(r"\"", '"')
+ # unicode-escape interprets \xhh as an escape sequence,
+ # but n3 does not define it as such.
+ value = value.replace(r"\x", r"\\x")
# Hack: this should correctly handle strings with either native unicode
# characters, or \u1234 unicode escapes.
value = value.encode("raw-unicode-escape").decode("unicode-escape")
