diff options
author | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-07-03 01:10:46 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 01:10:46 +1000 |
commit | f1498838d8c54898665d7684eab7cc6db7dc98fb (patch) | |
tree | cd43131bb9eefb1e5de0e8f23c2de87007e70466 /test | |
parent | 7c86efede775d62f7bc16d08d2ee4af7dde295d7 (diff) | |
parent | 50c3112a6f6c91efac8bdae265c4b9823d9a8a75 (diff) | |
download | rdflib-f1498838d8c54898665d7684eab7cc6db7dc98fb.tar.gz |
Merge pull request #1343 from iafork/iwana-issue549
Prevent `from_n3` from unescaping `\xhh`
Diffstat (limited to 'test')
-rw-r--r-- | test/test_util.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/test_util.py b/test/test_util.py index ea3b122e..62cb52db 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -2,6 +2,7 @@ import unittest import time +from unittest.case import expectedFailure from rdflib.graph import Graph from rdflib.graph import QuotedGraph from rdflib.graph import ConjunctiveGraph @@ -301,6 +302,47 @@ class TestUtilTermConvert(unittest.TestCase): res = util.from_n3(s, default=None, backend="Memory") self.assertTrue(isinstance(res, Graph)) + def test_util_from_n3_escapes(self) -> None: + pairs = [ + ("\\t", "\t"), + ("\\b", "\b"), + ("\\n", "\n"), + ("\\r", "\r"), + ("\\f", "\f"), + ('\\"', '"'), + ("\\'", "'"), + ("\\\\", "\\"), + ("\\u00F6", "ö"), + ("\\U000000F6", "ö"), + ] + for escaped, raw in pairs: + with self.subTest(f"{escaped} => {raw}"): + literal_str = str(util.from_n3(f'"{escaped}"')) + self.assertEqual(literal_str, f"{raw}") + + def test_util_from_n3_not_escapes(self) -> None: + strings = [ + "jörn", + "j\\xf6rn", + ] + for string in strings: + with self.subTest(f"{string}"): + literal_str = str(util.from_n3(f'"{string}"')) + self.assertEqual(literal_str, f"{string}") + + @expectedFailure + def test_util_from_n3_not_escapes_xf(self) -> None: + strings = [ + f"j\\366rn", + f"\\", + f"\\0", + f"\\I", + ] + for string in strings: + with self.subTest(f"{string}"): + literal_str = str(util.from_n3(f'"{string}"')) + self.assertEqual(literal_str, f"{string}") + class TestUtilCheckers(unittest.TestCase): def setUp(self): |