From 8c9608b4e9db07085884e705579307ef6a3e8d48 Mon Sep 17 00:00:00 2001 From: WhiteGobo Date: Wed, 5 Jul 2023 22:03:14 +0200 Subject: [PATCH] fix: TriG handling of GRAPH keyword without a graph ID (#2469) The RDF 1.1 TriG grammar only allows the `GRAPH` keyword if it is followed by a graph identifier [[ref](https://www.w3.org/TR/trig/#grammar-production-block)]. This change enforces this rule so that the test passes. --------- Co-authored-by: WhiteGobo Co-authored-by: Iwan Aucamp --- 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 71593b5ce..cc4cf131e 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: + self.BadSyntax(argstr, i, "GRAPH keyword must be followed by graph name") 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 d7c843340..9f49616fb 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" - ), } diff --git a/test_reports/rdflib_w3c_trig-HEAD.ttl b/test_reports/rdflib_w3c_trig-HEAD.ttl index 78a28d61c..02e67f8f2 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 .