From 074adcc5f97c27e4fd3ec62e21903c594e79aa06 Mon Sep 17 00:00:00 2001 From: Nicholas Car Date: Mon, 16 Mar 2020 11:15:13 +1000 Subject: [PATCH] Issue 920 fixes as per Issue desc, + test --- rdflib/plugins/parsers/ntriples.py | 2 +- test/test_issue920.py | 36 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 test/test_issue920.py diff --git a/rdflib/plugins/parsers/ntriples.py b/rdflib/plugins/parsers/ntriples.py index 99b966b1b..67dbe9d7b 100644 --- a/rdflib/plugins/parsers/ntriples.py +++ b/rdflib/plugins/parsers/ntriples.py @@ -28,7 +28,7 @@ __all__ = ['unquote', 'uriquote', 'Sink', 'NTriplesParser'] -uriref = r'<([^:]+:[^\s"<>]+)>' +uriref = r'<([^:]+:[^\s"<>]*)>' literal = r'"([^"\\]*(?:\\.[^"\\]*)*)"' litinfo = r'(?:@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)|\^\^' + uriref + r')?' diff --git a/test/test_issue920.py b/test/test_issue920.py new file mode 100644 index 000000000..eb12edc49 --- /dev/null +++ b/test/test_issue920.py @@ -0,0 +1,36 @@ +""" +Issue 920 - NTriples fails to parse URIs with only a scheme + +from rdflib import Graph +g=Graph() +g.parse(data=' .', format='nt') # nquads also fails + +N3, by contrast, succeeds: + +g.parse(data=' .', format='n3') +""" +from rdflib import Graph +import unittest + + +class TestIssue920(unittest.TestCase): + + def test_issue_920(self): + g = Graph() + # NT tests + g.parse(data=' .', format='nt') + g.parse(data=' .', format='nt') + g.parse(data=' .', format='nt') + + # related parser tests + g.parse(data=' .', format='turtle') + g.parse(data=' .', format='turtle') + g.parse(data=' .', format='turtle') + + g.parse(data=' .', format='n3') + g.parse(data=' .', format='n3') + g.parse(data=' .', format='n3') + + +if __name__ == "__main__": + unittest.main()