Skip to content

Commit 2613c4a

Browse files
committed
Keep term definitions mapping to null so they may be protected.
1 parent 280a01e commit 2613c4a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
- Terms of the form of an IRI must map to the same IRI.
1414
- Terms of the form of a relative IRI may not be used as prefixes.
1515

16+
### Changed
17+
- Keep term definitions mapping to null so they may be protected.
18+
1619
## 2.0.0 - 2019-12-09
1720

1821
### Notes

lib/context.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,9 @@ api.createTermDefinition = ({
365365
activeCtx.mappings.delete(term);
366366
}
367367

368-
// clear context entry
369-
if(value === null || (_isObject(value) && value['@id'] === null)) {
370-
activeCtx.mappings.set(term, null);
371-
defined.set(term, true);
372-
return;
373-
}
374-
375368
// convert short-hand value to object w/@id
376369
let simpleTerm = false;
377-
if(_isString(value)) {
370+
if(_isString(value) || value === null) {
378371
simpleTerm = true;
379372
value = {'@id': value};
380373
}
@@ -448,13 +441,16 @@ api.createTermDefinition = ({
448441
mapping.reverse = true;
449442
} else if('@id' in value) {
450443
let id = value['@id'];
451-
if(!_isString(id)) {
444+
if(id && !_isString(id)) {
452445
throw new JsonLdError(
453446
'Invalid JSON-LD syntax; a @context @id value must be an array ' +
454447
'of strings or a string.',
455448
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
456449
}
457-
if(id !== term) {
450+
if(id === null) {
451+
// reserve a null term, which may be protected
452+
mapping['@id'] = null;
453+
} else if(id !== term) {
458454
// expand and add @id mapping
459455
id = _expandIri(
460456
activeCtx, id, {vocab: true, base: false}, localCtx, defined, options);
@@ -470,10 +466,12 @@ api.createTermDefinition = ({
470466
if(term.match(/(?::[^:])|\//)) {
471467
const termDefined = new Map(defined).set(term, true);
472468
const termIri = _expandIri(
473-
activeCtx, term, {vocab: true, base: false}, localCtx, termDefined, options);
469+
activeCtx, term, {vocab: true, base: false},
470+
localCtx, termDefined, options);
474471
if(termIri !== id) {
475472
throw new JsonLdError(
476-
'Invalid JSON-LD syntax; term in form of IRI must expand to definition.',
473+
'Invalid JSON-LD syntax; term in form of IRI must ' +
474+
'expand to definition.',
477475
'jsonld.SyntaxError',
478476
{code: 'invalid IRI mapping', context: localCtx});
479477
}
@@ -942,6 +940,9 @@ api.getInitialContext = options => {
942940
let container = mapping['@container'] || '@none';
943941
container = [].concat(container).sort().join('');
944942

943+
if(mapping['@id'] === null) {
944+
continue;
945+
}
945946
// iterate over every IRI in the mapping
946947
const ids = _asArray(mapping['@id']);
947948
for(const iri of ids) {

tests/test-common.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ const TEST_TYPES = {
100100
/expand-manifest.jsonld#thc03$/,
101101
/expand-manifest.jsonld#thc04$/,
102102
/expand-manifest.jsonld#thc05$/,
103-
// protected null IRI mapping
104-
/expand-manifest.jsonld#tpr28$/,
105103
// remote
106104
/remote-doc-manifest.jsonld#t0005$/,
107105
/remote-doc-manifest.jsonld#t0006$/,
@@ -373,8 +371,6 @@ const TEST_TYPES = {
373371
/toRdf-manifest.jsonld#tpi09$/,
374372
/toRdf-manifest.jsonld#tpi10$/,
375373
/toRdf-manifest.jsonld#tpi11$/,
376-
// protected null IRI mapping
377-
/toRdf-manifest.jsonld#tpr28$/,
378374
// prefix
379375
/toRdf-manifest.jsonld#tpr29$/,
380376
// @import

0 commit comments

Comments
 (0)