Skip to content

Commit fee4d75

Browse files
gkelloggdavidlehn
authored andcommitted
- Terms of the form of an IRI must map to the same IRI.
- Terms of the form of a relative IRI may not be used as prefixes.
1 parent 02ec279 commit fee4d75

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
- JSON literal value handling issues.
1717
- Do minimal checking to see if IRIs are valid by making sure they contain
1818
no whitespace.
19+
- Terms of the form of an IRI must map to the same IRI.
20+
- Terms of the form of a relative IRI may not be used as prefixes.
1921

2022
## 2.0.0 - 2019-12-09
2123

lib/context.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,20 @@ api.createTermDefinition = ({
465465
'jsonld.SyntaxError',
466466
{code: 'invalid IRI mapping', context: localCtx});
467467
}
468+
469+
// if term has the form of an IRI it must map the same
470+
if(term.match(/(?::[^:])|\//)) {
471+
const termDefined = new Map(defined).set(term, true);
472+
const termIri = _expandIri(
473+
activeCtx, term, {vocab: true, base: false}, localCtx, termDefined, options);
474+
if(termIri !== id) {
475+
throw new JsonLdError(
476+
'Invalid JSON-LD syntax; term in form of IRI must expand to definition.',
477+
'jsonld.SyntaxError',
478+
{code: 'invalid IRI mapping', context: localCtx});
479+
}
480+
}
481+
468482
mapping['@id'] = id;
469483
// indicate if this term may be used as a compact IRI prefix
470484
mapping._prefix = (simpleTerm &&
@@ -685,7 +699,7 @@ api.createTermDefinition = ({
685699

686700
// term may be used as a prefix
687701
if('@prefix' in value) {
688-
if(mapping._termHasColon) {
702+
if(term.match(/:|\//)) {
689703
throw new JsonLdError(
690704
'Invalid JSON-LD syntax; @context @prefix used on a compact IRI term',
691705
'jsonld.SyntaxError',
@@ -808,7 +822,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
808822
return null;
809823
}
810824

811-
if(mapping) {
825+
if(_isObject(mapping) && '@id' in mapping) {
812826
// value is a term
813827
return mapping['@id'];
814828
}

tests/test-common.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ const TEST_TYPES = {
100100
/expand-manifest.jsonld#thc03$/,
101101
/expand-manifest.jsonld#thc04$/,
102102
/expand-manifest.jsonld#thc05$/,
103-
// misc
104-
/expand-manifest.jsonld#te043$/,
105-
/expand-manifest.jsonld#te044$/,
106-
/expand-manifest.jsonld#te048$/,
107-
/expand-manifest.jsonld#te049$/,
108103
// protected null IRI mapping
109104
/expand-manifest.jsonld#tpr28$/,
110105
// remote

0 commit comments

Comments
 (0)