Skip to content

libtracker-sparql: Escape illegal characters in IRIREF from TrackerResource

Carlos Garnacho requested to merge wip/carlosg/resource-iri-escapes into master

Currently, all IRIREF going through SPARQL updates will be validated for the characters being in the expected set (https://www.w3.org/TR/sparql11-query/#rIRIREF), meanwhile TrackerResource is pretty liberal in the characters used by a TrackerResource identifier or IRI reference.

This disagreement causes has 2 possible outcomes:

  • If the resource is inserted via print_sparql_update(), print_rdf() or alike while containing illegal characters, it will find errors when handling the SPARQL update.

  • If the resource is directly inserted via TrackerBatch or update_resource(), the validation step will be bypassed, ending up with an IRI that contains illegal characters as per the SPARQL grammar.

In order to make TrackerResource friendly to e.g. sloppy IRI composition and avoid these ugly situations when an illegal char sneaks in, make it escape the IRIs as defined by IRIREF in the SPARQL grammar definition. This way every method of insertion will succeed and be most correct with the given input.

Also, add tests for this behavior, to ensure we escape what should be escaped.

Merge request reports