Skip to content

Commit

Permalink
Merge pull request #16 from jeswr/fix/relative-uri
Browse files Browse the repository at this point in the history
fix: correctly generate relative uri's
  • Loading branch information
jeswr authored Dec 31, 2022
2 parents 7ef7f8a + ef26860 commit 077ebe9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 4 additions & 0 deletions __tests__/valid/basic-shape-iri-relative.shaclc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BASE <http://example.org/test>

shape <#TestShape> {
}
10 changes: 10 additions & 0 deletions __tests__/valid/basic-shape-iri-relative.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

<http://example.org/test>
a owl:Ontology ;
.

<http://example.org/test#TestShape>
a sh:NodeShape ;
.
16 changes: 6 additions & 10 deletions lib/shaclc.jison
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,23 @@
return iri;
if (!Parser.base)
throw new Error('Cannot resolve relative IRI ' + iri + ' because no base IRI was set.');
if (!base) {
base = Parser.base;
basePath = base.replace(/[^\/:]*$/, '');
baseRoot = base.match(/^(?:[a-z]+:\/*)?[^\/]*/)[0];
}
switch (iri[0]) {
// An empty relative IRI indicates the base IRI
case undefined:
return base;
return base.value;
// Resolve relative fragment IRIs against the base IRI
case '#':
return base + iri;
return base.value + iri;
// Resolve relative query string IRIs by replacing the query string
case '?':
return base.replace(/(?:\?.*)?$/, iri);
return base.value.replace(/(?:\?.*)?$/, iri);
// Resolve root relative IRIs at the root of the base IRI
case '/':
return baseRoot + iri;
return base.value.replace(/[^\/:]*$/, '') + iri;
// Resolve all other IRIs at the base IRI's path
default:
return basePath + iri;
return base.value.match(/^(?:[a-z]+:\/*)?[^\/]*/)[0] + iri;
}
}
Expand Down

0 comments on commit 077ebe9

Please sign in to comment.