From d7c4e4b4d78fbc0692fa57c1ea4896314a2d1cc2 Mon Sep 17 00:00:00 2001 From: "David I. Lehn" Date: Thu, 27 Feb 2020 13:44:27 -0500 Subject: [PATCH] Fix handling of `@` values for `@reverse`. --- CHANGELOG.md | 1 + lib/context.js | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a1b5e2e..95c4fed8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - Match spec error code "invalid context entry" vs "invalid context member". - Keywords may not be used as prefixes. - Handle term definition on `@type` with empty map. +- Handling of `@` values for `@reverse`. ### Changed - Keep term definitions mapping to null so they may be protected. diff --git a/lib/context.js b/lib/context.js index 09d903f0..b5b1dcd6 100644 --- a/lib/context.js +++ b/lib/context.js @@ -506,18 +506,7 @@ api.createTermDefinition = ({ 'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx}); } - // expand and add @id mapping - const id = _expandIri( - activeCtx, reverse, {vocab: true, base: false}, localCtx, defined, - options); - if(!_isAbsoluteIri(id)) { - throw new JsonLdError( - 'Invalid JSON-LD syntax; a @context @reverse value must be an ' + - 'absolute IRI or a blank node identifier.', - 'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx}); - } - - if(reverse.match(KEYWORD_PATTERN)) { + if(!api.isKeyword(reverse) && reverse.match(KEYWORD_PATTERN)) { // FIXME: remove logging and use a handler console.warn('WARNING: values beginning with "@" are reserved' + ' for future use and ignored', {reverse}); @@ -529,6 +518,17 @@ api.createTermDefinition = ({ return; } + // expand and add @id mapping + const id = _expandIri( + activeCtx, reverse, {vocab: true, base: false}, localCtx, defined, + options); + if(!_isAbsoluteIri(id)) { + throw new JsonLdError( + 'Invalid JSON-LD syntax; a @context @reverse value must be an ' + + 'absolute IRI or a blank node identifier.', + 'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx}); + } + mapping['@id'] = id; mapping.reverse = true; } else if('@id' in value) {