Skip to content

Commit 717ef40

Browse files
bovlbashleysommer
andauthored
Fix parser bug and add test (#2943)
* Fix parser bug and add test * Fix import order in unrelated file to make CI happy * Simply fix, add explanatory comment * Apply black formatter --------- Co-authored-by: Ashley Sommer <[email protected]>
1 parent 82c2421 commit 717ef40

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

rdflib/plugins/sparql/parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ def expandTriples(terms: ParseResults) -> List[Any]:
8181
if len(t) > 1:
8282
res += t # Don't update last_subject/last_predicate
8383
# is this bnode the subject of more triples?
84-
if i + 1 < l_ and terms[i + 1] not in ".,;":
84+
if i + 1 < l_ and terms[i + 1] not in [
85+
".",
86+
",",
87+
";",
88+
]: # term might not be a string
8589
last_subject, last_predicate = t[0], None
8690
res.append(t[0])
8791
elif isinstance(t, ParseResults):
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
PREFIX : <http://example.org/>
2+
SELECT ?x ?y WHERE {
3+
[ :p1 ?x ] :p2 ?y .
4+
}

test/test_sparql/test_translate_algebra.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ def _format_query(query: str) -> str:
105105
"test_graph_patterns__bgp",
106106
"Test if basic graph patterns are properly translated into the query text.",
107107
),
108+
AlgebraTest(
109+
"test_graph_patterns__bnode_subject",
110+
"Test if a blank node subject gets properly translated into the query text.",
111+
),
108112
AlgebraTest(
109113
"test_graph_patterns__extend",
110114
'Test if "extend" (=Bind explicitly or implicitly in projection)'

0 commit comments

Comments
 (0)