From ffbddb6a3d29fe4eacbfe273c2f5433e2a4fae1c Mon Sep 17 00:00:00 2001 From: WhiteGobo Date: Tue, 4 Jul 2023 14:29:58 +0200 Subject: [PATCH 1/2] if GRAPH is used as keyword in trig, then a graphname must be given as described in test https://www.w3.org/2013/TrigTests/#trig-graph-bad-01 --- rdflib/plugins/parsers/trig.py | 4 ++++ test/test_w3c_spec/test_trig_w3c.py | 3 --- test_reports/rdflib_w3c_trig-HEAD.ttl | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/rdflib/plugins/parsers/trig.py b/rdflib/plugins/parsers/trig.py index d28198bce..0ade8a115 100644 --- a/rdflib/plugins/parsers/trig.py +++ b/rdflib/plugins/parsers/trig.py @@ -69,16 +69,20 @@ def graph(self, argstr: str, i: int) -> int: raise Exception if it looks like a graph, but isn't. """ + need_graphid = False # import pdb; pdb.set_trace() j = self.sparqlTok("GRAPH", argstr, i) # optional GRAPH keyword if j >= 0: i = j + need_graphid = True r: MutableSequence[Any] = [] j = self.labelOrSubject(argstr, i, r) if j >= 0: graph = r[0] i = j + elif need_graphid: + return -1 else: graph = self._store.graph.identifier # hack diff --git a/test/test_w3c_spec/test_trig_w3c.py b/test/test_w3c_spec/test_trig_w3c.py index ea2b02edd..74aa66f18 100644 --- a/test/test_w3c_spec/test_trig_w3c.py +++ b/test/test_w3c_spec/test_trig_w3c.py @@ -173,9 +173,6 @@ def check_entry(entry: ManifestEntry) -> None: f"{REMOTE_BASE_IRI}#trig-syntax-bad-list-04": pytest.mark.xfail( reason="ignores badly formed quad" ), - f"{REMOTE_BASE_IRI}#trig-graph-bad-01": pytest.mark.xfail( - reason="accepts GRAPH with no name" - ), f"{REMOTE_BASE_IRI}#trig-graph-bad-07": pytest.mark.xfail( reason="accepts nested GRAPH" ), diff --git a/test_reports/rdflib_w3c_trig-HEAD.ttl b/test_reports/rdflib_w3c_trig-HEAD.ttl index 7c22104d2..71f67e714 100644 --- a/test_reports/rdflib_w3c_trig-HEAD.ttl +++ b/test_reports/rdflib_w3c_trig-HEAD.ttl @@ -923,7 +923,7 @@ earl:assertedBy ; earl:mode earl:automatic ; earl:result [ a earl:TestResult ; - earl:outcome earl:failed ] ; + earl:outcome earl:passed ] ; earl:subject ; earl:test . From 0f5da49859de73fb8afd6abe3f09e71e3265a508 Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Wed, 5 Jul 2023 13:28:51 +0200 Subject: [PATCH 2/2] Update rdflib/plugins/parsers/trig.py --- rdflib/plugins/parsers/trig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rdflib/plugins/parsers/trig.py b/rdflib/plugins/parsers/trig.py index 0ade8a115..d212da68f 100644 --- a/rdflib/plugins/parsers/trig.py +++ b/rdflib/plugins/parsers/trig.py @@ -82,7 +82,7 @@ def graph(self, argstr: str, i: int) -> int: graph = r[0] i = j elif need_graphid: - return -1 + self.BadSyntax(argstr, i, "GRAPH keyword must be followed by graph name") else: graph = self._store.graph.identifier # hack