Skip to content

Commit 8c9608b

Browse files
WhiteGoboaucampia
andauthored
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 <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>
1 parent 9a901ae commit 8c9608b

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

rdflib/plugins/parsers/trig.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,20 @@ def graph(self, argstr: str, i: int) -> int:
6969
raise Exception if it looks like a graph, but isn't.
7070
"""
7171

72+
need_graphid = False
7273
# import pdb; pdb.set_trace()
7374
j = self.sparqlTok("GRAPH", argstr, i) # optional GRAPH keyword
7475
if j >= 0:
7576
i = j
77+
need_graphid = True
7678

7779
r: MutableSequence[Any] = []
7880
j = self.labelOrSubject(argstr, i, r)
7981
if j >= 0:
8082
graph = r[0]
8183
i = j
84+
elif need_graphid:
85+
self.BadSyntax(argstr, i, "GRAPH keyword must be followed by graph name")
8286
else:
8387
graph = self._store.graph.identifier # hack
8488

test/test_w3c_spec/test_trig_w3c.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ def check_entry(entry: ManifestEntry) -> None:
173173
f"{REMOTE_BASE_IRI}#trig-syntax-bad-list-04": pytest.mark.xfail(
174174
reason="ignores badly formed quad"
175175
),
176-
f"{REMOTE_BASE_IRI}#trig-graph-bad-01": pytest.mark.xfail(
177-
reason="accepts GRAPH with no name"
178-
),
179176
}
180177

181178

test_reports/rdflib_w3c_trig-HEAD.ttl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@
923923
earl:assertedBy <https://github.com/RDFLib/rdflib> ;
924924
earl:mode earl:automatic ;
925925
earl:result [ a earl:TestResult ;
926-
earl:outcome earl:failed ] ;
926+
earl:outcome earl:passed ] ;
927927
earl:subject <https://github.com/RDFLib/rdflib> ;
928928
earl:test <http://www.w3.org/2013/TriGTests/#trig-graph-bad-01> .
929929

0 commit comments

Comments
 (0)