ad-freiburg / qlever

Very fast SPARQL Engine, which can handle very large knowledge graphs like the complete Wikidata, offers context-sensitive autocompletion for SPARQL queries, and allows combination with text search. It's faster than engines like Blazegraph or Virtuoso, especially for queries involving large result sets.
Apache License 2.0
376 stars 45 forks source link

Direct POST of SPARQL queries not working correctly when ampersand (&) is involved. #1493

Open Aklakan opened 2 weeks ago

Aklakan commented 2 weeks ago

Hi,

There is an issue when sending an unencoded SPARQL query with Content-Type: application/sparql-query. Some characters cause issues then (see below).

Because Apache Jena uses this approach for longer query strings it would be very useful if that worked frictionlessly for interoperability.

According to the SPARQL specification

2.1.3 query via POST directly

Protocol clients may send protocol requests via the HTTP POST method by including the query directly and unencoded as the HTTP request message body. When using this approach, clients must include the SPARQL query string, unencoded, and nothing else as the message body of the request. Clients must set the content type header of the HTTP request to application/sparql-query. Clients may include the optional default-graph-uri and named-graph-uri parameters as HTTP query string parameters in the request URI. Note that UTF-8 is the only valid charset here.

POST with form encoding (works)

curl http://localhost:7001 --data-urlencode 'query=SELECT ?s { ?s a ?o FILTER(true && true)} LIMIT 10'
{"head":{"vars":["s"]},"results":{"bindings":[{"s":{"type":"uri","value":"https://www.wikidata.org/wiki/Special:EntityData/P10"}}   }}

Direct POST without '&&' (works)

curl http://localhost:7001 -H 'Content-Type: application/sparql-query' --data 'SELECT ?s { ?s a ?o } LIMIT 10'
{"head":{"vars":["s"]},"results":{"bindings":[{"s":{"type":"uri","value":"https://www.wikidata.org/wiki/Special:EntityData/P10"}}   }}

Direct POST with '&&' (fails)

curl http://localhost:7001 -H 'Content-Type: application/sparql-query' --data 'SELECT ?s { ?s a ?o FILTER(true && true)} LIMIT 10'
Parameter without "=" in HTTP Request. . In file "/app/src/util/http/UrlParser.cpp " at line 100

Not sure whether there are further characters that cause problems; in any case there is some issue with encoding/decoding of chars.