Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the use of $PATH, or string interpolation of SHACL paths #163

Open
VladimirAlexiev opened this issue Jan 1, 2025 · 3 comments
Open
Labels
SPARQL For SHACL 1.2 SPARQL extensions spec

Comments

@VladimirAlexiev
Copy link

VladimirAlexiev commented Jan 1, 2025

Sec 5.2 Syntax of SPARQL-based Constraints:

SELECT queries used in the context of property shapes use a special variable named PATH as a placeholder for the path used by the shape.

The only legal use of the variable PATH in the SPARQL queries of SPARQL-based constraints and SELECT-based validators is in the predicate position of a triple pattern.

But if sh:path is complex (not a predicate), it cannot be used in this way.

So I suggest adding two clarifications:

  • "(spelled in UPPERCASE)" because SPARQL var names are case-sensitive
  • "This can only be used with simple sh:path that consists of a single predicate. For complex sh:path, write the property path in SPARQL syntax in the query."
@VladimirAlexiev VladimirAlexiev changed the title Clarify the use of Clarify the use of $PATH Jan 1, 2025
@afs
Copy link

afs commented Jan 1, 2025

If the sh:path is complex, and $PATH is correctly used (predicate position of a triple pattern), then it converting a SHACL path to SPARQL string syntax, and then doing string substitution should work.

That said, such string substitution can be an injection attack vector and that would be a principled reason to not allow complex paths. (Value injection is a safe mechanism for injecting into a query.)

@VladimirAlexiev
Copy link
Author

VladimirAlexiev commented Jan 2, 2025

I agree that converting a SHACL path to SPARQL string syntax would be a very useful feature, and it would enable the use of a lot more general SPARQL templates.
Changed the title of this issue accordingly.

I'm not very worried about SPARQL injection because we're not talking random strings here. An engine should check that sh:path corresponds to the syntax for SHACL paths and if not, then it can emit eg "BAD-PATH" or something similar.

So what do others think, should the new spec require it from engines? https://www.w3.org/TR/shacl/#dfn-path-mapping is already defined, what we're talking about is taking the mapping result and interpolating it in sh:select

@VladimirAlexiev VladimirAlexiev changed the title Clarify the use of $PATH Clarify the use of $PATH, or string interpolation of SHACL paths Jan 2, 2025
@VladimirAlexiev
Copy link
Author

A bit related: #165

@HolgerKnublauch HolgerKnublauch added the SPARQL For SHACL 1.2 SPARQL extensions spec label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SPARQL For SHACL 1.2 SPARQL extensions spec
Projects
None yet
Development

No branches or pull requests

3 participants