Skip to content

Commit

Permalink
fix: TriG handling of GRAPH keyword without a graph ID (#2469)
Browse files Browse the repository at this point in the history
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
<http://www.w3.org/2013/TriGTests/#trig-graph-bad-01> test passes.

---------

Co-authored-by: WhiteGobo <richardfechner@posteo.net>
Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
  • Loading branch information
3 people committed Jul 5, 2023
1 parent 9a901ae commit 8c9608b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 4 additions & 0 deletions rdflib/plugins/parsers/trig.py
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions test/test_w3c_spec/test_trig_w3c.py
Expand Up @@ -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"
),
}


Expand Down
2 changes: 1 addition & 1 deletion test_reports/rdflib_w3c_trig-HEAD.ttl
Expand Up @@ -923,7 +923,7 @@
earl:assertedBy <https://github.com/RDFLib/rdflib> ;
earl:mode earl:automatic ;
earl:result [ a earl:TestResult ;
earl:outcome earl:failed ] ;
earl:outcome earl:passed ] ;
earl:subject <https://github.com/RDFLib/rdflib> ;
earl:test <http://www.w3.org/2013/TriGTests/#trig-graph-bad-01> .

Expand Down

0 comments on commit 8c9608b

Please sign in to comment.