From afea615557346347145128f77478b013ffcc0d45 Mon Sep 17 00:00:00 2001 From: WhiteGobo Date: Wed, 5 Jul 2023 20:57:16 +0200 Subject: [PATCH] fix: TriG parser error handling for nested graphs (#2468) Raise an error when nested graphs occur in TriG. With this change, the test passes. --------- Co-authored-by: WhiteGobo Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Iwan Aucamp --- rdflib/plugins/parsers/trig.py | 3 +++ test/test_w3c_spec/test_trig_w3c.py | 3 --- test_reports/rdflib_w3c_trig-HEAD.ttl | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rdflib/plugins/parsers/trig.py b/rdflib/plugins/parsers/trig.py index d28198bce..71593b5ce 100644 --- a/rdflib/plugins/parsers/trig.py +++ b/rdflib/plugins/parsers/trig.py @@ -98,6 +98,9 @@ def graph(self, argstr: str, i: int) -> int: j = i + 1 + if self._context is not None: + self.BadSyntax(argstr, i, "Nested graphs are not allowed") + oldParentContext = self._parentContext self._parentContext = self._context reason2 = self._reason2 diff --git a/test/test_w3c_spec/test_trig_w3c.py b/test/test_w3c_spec/test_trig_w3c.py index ea2b02edd..d7c843340 100644 --- a/test/test_w3c_spec/test_trig_w3c.py +++ b/test/test_w3c_spec/test_trig_w3c.py @@ -176,9 +176,6 @@ def check_entry(entry: ManifestEntry) -> None: 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..78a28d61c 100644 --- a/test_reports/rdflib_w3c_trig-HEAD.ttl +++ b/test_reports/rdflib_w3c_trig-HEAD.ttl @@ -971,7 +971,7 @@ earl:assertedBy ; earl:mode earl:automatic ; earl:result [ a earl:TestResult ; - earl:outcome earl:failed ] ; + earl:outcome earl:passed ] ; earl:subject ; earl:test .