From 1cfcfda8c4fa240ced782bb061f61b81c30e1410 Mon Sep 17 00:00:00 2001 From: Gunnar Aastrand Grimnes Date: Mon, 30 Dec 2013 17:16:26 +0100 Subject: [PATCH] added test and fixed #312 --- rdflib/plugins/parsers/notation3.py | 7 +++++-- test/test_n3.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py index caa75b019..fb61b04af 100644 --- a/rdflib/plugins/parsers/notation3.py +++ b/rdflib/plugins/parsers/notation3.py @@ -1165,8 +1165,11 @@ def uri_ref2(self, argstr, i, res): if pfx == "_": # Magic prefix 2001/05/30, can be changed res.append(self.anonymousNode(ln)) return j - self.BadSyntax(argstr, i, - "Prefix \"%s:\" not bound" % (pfx)) + if not self.turtle and pfx == "": + ns = join(self._baseURI or "", "#") + else: + self.BadSyntax(argstr, i, + "Prefix \"%s:\" not bound" % (pfx)) symb = self._store.newSymbol(ns + ln) if symb in self._variables: res.append(self._variables[symb]) diff --git a/test/test_n3.py b/test/test_n3.py index d6fc1f2d8..3255df254 100644 --- a/test/test_n3.py +++ b/test/test_n3.py @@ -218,5 +218,16 @@ def testSingleQuotedLiterals(self): for _, _, o in g: self.assertEqual(o, Literal('o')) + def testEmptyPrefix(self): + + # this is issue https://github.com/RDFLib/rdflib/issues/312 + g1 = Graph() + g1.parse(data = ":a :b :c .", format='n3') + + g2 = Graph() + g2.parse(data = "@prefix : <#> . :a :b :c .", format='n3') + + assert set(g1) == set(g2), 'Document with declared empty prefix must match default #' + if __name__ == '__main__': unittest.main()