Skip to content

Commit f4815cb

Browse files
committed
Fix handling of @ values for @reverse.
1 parent 6d7a453 commit f4815cb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Match spec error code "invalid context entry" vs "invalid context member".
1616
- Keywords may not be used as prefixes.
1717
- Handle term definition on `@type` with empty map.
18+
- Handling of `@` values for `@reverse`.
1819

1920
### Changed
2021
- Keep term definitions mapping to null so they may be protected.

lib/context.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -506,18 +506,7 @@ api.createTermDefinition = ({
506506
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
507507
}
508508

509-
// expand and add @id mapping
510-
const id = _expandIri(
511-
activeCtx, reverse, {vocab: true, base: false}, localCtx, defined,
512-
options);
513-
if(!_isAbsoluteIri(id)) {
514-
throw new JsonLdError(
515-
'Invalid JSON-LD syntax; a @context @reverse value must be an ' +
516-
'absolute IRI or a blank node identifier.',
517-
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
518-
}
519-
520-
if(reverse.match(KEYWORD_PATTERN)) {
509+
if(!api.isKeyword(reverse) && reverse.match(KEYWORD_PATTERN)) {
521510
// FIXME: remove logging and use a handler
522511
console.warn('WARNING: values beginning with "@" are reserved' +
523512
' for future use and ignored', {reverse});
@@ -529,6 +518,17 @@ api.createTermDefinition = ({
529518
return;
530519
}
531520

521+
// expand and add @id mapping
522+
const id = _expandIri(
523+
activeCtx, reverse, {vocab: true, base: false}, localCtx, defined,
524+
options);
525+
if(!_isAbsoluteIri(id)) {
526+
throw new JsonLdError(
527+
'Invalid JSON-LD syntax; a @context @reverse value must be an ' +
528+
'absolute IRI or a blank node identifier.',
529+
'jsonld.SyntaxError', {code: 'invalid IRI mapping', context: localCtx});
530+
}
531+
532532
mapping['@id'] = id;
533533
mapping.reverse = true;
534534
} else if('@id' in value) {

0 commit comments

Comments
 (0)