Skip to content

Commit e23f78d

Browse files
gkelloggdavidlehn
authored andcommitted
Check for keys in term definition outside that expected: @container, @id, @language, @reverse, and @type. This also sets up for additional keywords in 1.1.
1 parent 97292bc commit e23f78d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/context.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,31 @@ api.createTermDefinition = (activeCtx, localCtx, term, defined) => {
260260
const mapping = activeCtx.mappings[term] = {};
261261
mapping.reverse = false;
262262

263+
// make sure term definition only has expected keywords
264+
const validKeys = ['@container', '@id', '@language', '@reverse', '@type'];
265+
266+
for(let kw in value) {
267+
if(!validKeys.includes(kw)) {
268+
throw new JsonLdError(
269+
'Invalid JSON-LD syntax; a term definition must not contain ' + kw,
270+
'jsonld.SyntaxError',
271+
{code: 'invalid term definition', context: localCtx});
272+
}
273+
}
274+
263275
if('@reverse' in value) {
264276
if('@id' in value) {
265277
throw new JsonLdError(
266278
'Invalid JSON-LD syntax; a @reverse term definition must not ' +
267279
'contain @id.', 'jsonld.SyntaxError',
268280
{code: 'invalid reverse property', context: localCtx});
269281
}
282+
if('@nest' in value) {
283+
throw new JsonLdError(
284+
'Invalid JSON-LD syntax; a @reverse term definition must not ' +
285+
'contain @nest.', 'jsonld.SyntaxError',
286+
{code: 'invalid reverse property', context: localCtx});
287+
}
270288
const reverse = value['@reverse'];
271289
if(!_isString(reverse)) {
272290
throw new JsonLdError(
@@ -442,6 +460,10 @@ api.createTermDefinition = (activeCtx, localCtx, term, defined) => {
442460
mapping['@language'] = language;
443461
}
444462

463+
if('@next' in value) {
464+
465+
}
466+
445467
// disallow aliasing @context and @preserve
446468
const id = mapping['@id'];
447469
if(id === '@context' || id === '@preserve') {
@@ -807,6 +829,7 @@ api.isKeyword = v => {
807829
case '@index':
808830
case '@language':
809831
case '@list':
832+
case '@nest':
810833
case '@omitDefault':
811834
case '@preserve':
812835
case '@requireAll':

0 commit comments

Comments
 (0)