Skip to content

Commit 9fef94e

Browse files
gkelloggdavidlehn
authored andcommitted
Check for compactIri yielding an absoluteIri where the scheme matches a term that can be used as a prefix.
1 parent 6c94c05 commit 9fef94e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/compact.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,17 @@ api.compactIri = ({
824824
return choice;
825825
}
826826

827+
// If iri could be confused with a compact IRI using a term in this context,
828+
// signal an error
829+
for(const [term, td] of activeCtx.mappings) {
830+
if(iri.startsWith(term + ':') && td._prefix) {
831+
throw new JsonLdError(
832+
('Absolute IRI "' + iri + '" confused with prefix "' + term + '"'),
833+
'jsonld.SyntaxError',
834+
{code: 'IRI confused with prefix', context: activeCtx});
835+
}
836+
}
837+
827838
// compact IRI relative to base
828839
if(!relativeTo.vocab) {
829840
return _removeBase(activeCtx['@base'], iri);

tests/test-common.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ const TEST_TYPES = {
4848
/compact-manifest.jsonld#tpi04$/,
4949
/compact-manifest.jsonld#tpi05$/,
5050
/compact-manifest.jsonld#tpi06$/,
51-
// IRI confusion
52-
/compact-manifest.jsonld#te002$/,
5351
// @propogate
5452
/compact-manifest.jsonld#tc026$/,
5553
/compact-manifest.jsonld#tc027$/,

0 commit comments

Comments
 (0)