diff --git a/.changeset/swift-cars-flow.md b/.changeset/swift-cars-flow.md new file mode 100644 index 0000000..5c75140 --- /dev/null +++ b/.changeset/swift-cars-flow.md @@ -0,0 +1,5 @@ +--- +"rdf-validate-shacl": patch +--- + +Nodes targeted by `sh:targetNode` should fail validation even if they are not explicitly used in the Data Graph (fixes #107) diff --git a/src/shapes-graph.ts b/src/shapes-graph.ts index 9e6ba31..913612e 100644 --- a/src/shapes-graph.ts +++ b/src/shapes-graph.ts @@ -336,14 +336,7 @@ export class Shape { results.addAll(getInstancesOf(dataGraph.node(targetClass), ns)) }) - const targetNodes = this.shapeNodePointer.out(sh.targetNode).terms - // Ensure the node exists in data graph before considering it as a validatable target node - .filter((targetNode) => ( - dataGraph.dataset.match(targetNode).size > 0 || - dataGraph.dataset.match(null, targetNode).size > 0 || - dataGraph.dataset.match(null, null, targetNode).size > 0 - )) - results.addAll(targetNodes) + results.addAll(this.shapeNodePointer.out(sh.targetNode).terms) this.shapeNodePointer .out(sh.targetSubjectsOf) diff --git a/test/data/data-shapes/custom/manifest.ttl b/test/data/data-shapes/custom/manifest.ttl index fb78b47..689664a 100644 --- a/test/data/data-shapes/custom/manifest.ttl +++ b/test/data/data-shapes/custom/manifest.ttl @@ -9,7 +9,6 @@ mf:include ; mf:include ; mf:include ; - mf:include ; mf:include ; mf:include ; mf:include ; diff --git a/test/data/data-shapes/custom/targetNodeDoesNotExist-data.ttl b/test/data/data-shapes/custom/targetNodeDoesNotExist-data.ttl deleted file mode 100644 index 0d34d3c..0000000 --- a/test/data/data-shapes/custom/targetNodeDoesNotExist-data.ttl +++ /dev/null @@ -1 +0,0 @@ -# This data graph is empty on purpose diff --git a/test/data/data-shapes/custom/targetNodeDoesNotExist.ttl b/test/data/data-shapes/custom/targetNodeDoesNotExist.ttl deleted file mode 100644 index 1526f26..0000000 --- a/test/data/data-shapes/custom/targetNodeDoesNotExist.ttl +++ /dev/null @@ -1,32 +0,0 @@ -@prefix ex: . -@prefix mf: . -@prefix rdf: . -@prefix rdfs: . -@prefix sh: . -@prefix sht: . -@prefix xsd: . - -<> - rdf:type mf:Manifest ; - mf:entries ( ) ; -. - - - rdf:type sht:Validate ; - rdfs:label "Test of sh:targetNode absent from data graph" ; - mf:action [ - sht:dataGraph ; - sht:shapesGraph <> ; - ] ; - mf:result [ - rdf:type sh:ValidationReport ; - sh:conforms "true"^^xsd:boolean ; - ] ; - mf:status sht:proposed ; -. - -ex:MyShape - rdf:type sh:NodeShape ; - sh:targetNode ex:Instance1 ; - sh:class ex:TheClass ; -.