dsp-api icon indicating copy to clipboard operation
dsp-api copied to clipboard

GravsearchParser: check for elements that we do not allow for

Open tobiasschweizer opened this issue 6 years ago • 1 comments

GravsearchParser:

override def meet(node: algebra.ExtensionElem): Unit = {
            node.getExpr match {
                case valueConstant: algebra.ValueConstant =>
                    if (node.getName.startsWith("_const_")) {
                        // This is a parser-generated constant used in the CONSTRUCT clause. Just save it so we can
                        // build the CONSTRUCT clause correctly later.
                        valueConstants.put(node.getName, valueConstant)
                    } else {
                        // It's a BIND. Accept it if it refers to a Knora data IRI.
                        valueConstant.getValue match {
                            case iri: rdf4j.model.IRI =>
                                val variable = makeQueryVariable(node.getName)
                                val iriValue: IriRef = makeIri(iri)

                                if (!iriValue.iri.isKnoraDataIri) {
                                    throw GravsearchException(s"Unsupported IRI in BIND: ${iriValue.iri}")
                                }

                                val bindPattern = BindPattern(
                                    variable = variable,
                                    expression = iriValue
                                )

                                wherePatterns.append(bindPattern)

                            case other => throw GravsearchException(s"Unsupported value in BIND: $other")
                        }
                    }

                case _ => ()
            }
        }

The following should be rejected:

PREFIX incunabula: <http://0.0.0.0:3333/ontology/0803/incunabula/simple/v2#>
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/simple/v2#>

    CONSTRUCT {
        ?page knora-api:isMainResource true .

    } WHERE {

		BIND(SUBSTR(?fulltext, ?standoffStart, ?standoffEnd - ?standoffStart)
AS ?markedup)

    
    }

In a BIND, we only allow for Iris.

Check for everything that we allow for and ignore it if it is not needed for further processing (return Unit). Throw an error in all other cases.

tobiasschweizer avatar Nov 09 '18 13:11 tobiasschweizer

@mattssp thanks for reporting this!

tobiasschweizer avatar Nov 09 '18 14:11 tobiasschweizer