SPARQL: properly validates VALUE clauses

pull/304/head
Tpt 2 years ago committed by Thomas Tanon
parent a6de2e59a5
commit 0ccdea2ff1
  1. 8
      lib/spargebra/src/parser.rs
  2. 10
      testsuite/oxigraph-tests/sparql/manifest.ttl
  3. 1
      testsuite/oxigraph-tests/sparql/values_too_few.rq
  4. 1
      testsuite/oxigraph-tests/sparql/values_too_many.rq

@ -1441,8 +1441,12 @@ parser! {
rule InlineDataOneVar_value() -> Vec<Option<GroundTerm>> = t:DataBlockValue() _ { vec![t] } rule InlineDataOneVar_value() -> Vec<Option<GroundTerm>> = t:DataBlockValue() _ { vec![t] }
//[64] //[64]
rule InlineDataFull() -> (Vec<Variable>, Vec<Vec<Option<GroundTerm>>>) = "(" _ vars:InlineDataFull_var()* _ ")" _ "{" _ val:InlineDataFull_values()* "}" { rule InlineDataFull() -> (Vec<Variable>, Vec<Vec<Option<GroundTerm>>>) = "(" _ vars:InlineDataFull_var()* _ ")" _ "{" _ vals:InlineDataFull_values()* "}" {?
(vars, val) if vals.iter().all(|vs| vs.len() == vars.len()) {
Ok((vars, vals))
} else {
Err("The VALUES clause rows should have exactly the same number of values as there are variables. To set a value to undefined use UNDEF.")
}
} }
rule InlineDataFull_var() -> Variable = v:Var() _ { v } rule InlineDataFull_var() -> Variable = v:Var() _ { v }
rule InlineDataFull_values() -> Vec<Option<GroundTerm>> = "(" _ v:InlineDataFull_value()* _ ")" _ { v } rule InlineDataFull_values() -> Vec<Option<GroundTerm>> = "(" _ v:InlineDataFull_value()* _ ")" _ { v }

@ -28,6 +28,8 @@
:order_terms :order_terms
:nested_anonymous :nested_anonymous
:unbound_variable_in_subquery :unbound_variable_in_subquery
:values_too_many
:values_too_few
) . ) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ; :small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -129,3 +131,11 @@
mf:action mf:action
[ qt:query <unbound_variable_in_subquery.rq> ] ; [ qt:query <unbound_variable_in_subquery.rq> ] ;
mf:result <unbound_variable_in_subquery.srx> . mf:result <unbound_variable_in_subquery.srx> .
:values_too_many rdf:type mf:NegativeSyntaxTest11 ;
mf:name "Too many values in a VALUE clause compared to the number of variable" ;
mf:action <values_too_many.rq> .
:values_too_few rdf:type mf:NegativeSyntaxTest11 ;
mf:name "Too few values in a VALUE clause compared to the number of variable" ;
mf:action <values_too_few.rq> .

@ -0,0 +1 @@
SELECT * WHERE { VALUES (?a ?b) { (1) } }

@ -0,0 +1 @@
SELECT * WHERE { VALUES (?a ?b) { (1 2 3) } }
Loading…
Cancel
Save