Skip to content

Commit 6c94c05

Browse files
gkelloggdavidlehn
authored andcommitted
Use rval rather than activeCtx when processing @base and @vocab.
Resolve relative `@vocab` using expandIri with both vocab and base relative resolution. A relative `@vocab` is only invalid in 1.0.
1 parent 706ec1b commit 6c94c05

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
### Changed
1111
- Default processing mode changed to json-ld-1.1. Allows a 1.1 context to be
1212
used after non-1.1 contexts.
13+
- `@vocab` can be relative in 1.0, resolved against either a previous `@vocab`,
14+
`@base` or document base.
1315

1416
### Removed
1517
- **BREAKING**: Remove callback API support. This includes removing support

lib/context.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ api.process = async ({
194194

195195
// if not set explicitly, set processingMode to "json-ld-1.1"
196196
rval.processingMode =
197-
rval.processingMode || activeCtx.processingMode || 'json-ld-1.1';
197+
rval.processingMode || activeCtx.processingMode;
198198

199199
// handle @base
200200
if('@base' in ctx) {
@@ -205,7 +205,7 @@ api.process = async ({
205205
} else if(_isAbsoluteIri(base)) {
206206
base = parseUrl(base);
207207
} else if(_isRelativeIri(base)) {
208-
base = parseUrl(prependBase(activeCtx['@base'].href, base));
208+
base = parseUrl(prependBase(rval['@base'].href, base));
209209
} else {
210210
throw new JsonLdError(
211211
'Invalid JSON-LD syntax; the value of "@base" in a ' +
@@ -228,10 +228,14 @@ api.process = async ({
228228
'@context must be a string or null.',
229229
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx});
230230
} else if(!_isAbsoluteIri(value)) {
231-
throw new JsonLdError(
232-
'Invalid JSON-LD syntax; the value of "@vocab" in a ' +
233-
'@context must be an absolute IRI.',
234-
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx});
231+
if(api.processingMode(rval, 1.0)) {
232+
throw new JsonLdError(
233+
'Invalid JSON-LD syntax; the value of "@vocab" in a ' +
234+
'@context must be an absolute IRI.',
235+
'jsonld.SyntaxError', {code: 'invalid vocab mapping', context: ctx});
236+
}
237+
rval['@vocab'] = _expandIri(rval, value, {vocab: true, base: true},
238+
undefined, undefined, options);
235239
} else {
236240
rval['@vocab'] = value;
237241
}
@@ -1086,11 +1090,10 @@ api.getAllContexts = async (input, options) => {
10861090
*/
10871091
api.processingMode = (activeCtx, version) => {
10881092
if(version.toString() >= '1.1') {
1089-
return activeCtx.processingMode &&
1093+
return !activeCtx.processingMode ||
10901094
activeCtx.processingMode >= 'json-ld-' + version.toString();
10911095
} else {
1092-
return !activeCtx.processingMode ||
1093-
activeCtx.processingMode === 'json-ld-1.0';
1096+
return activeCtx.processingMode === 'json-ld-1.0';
10941097
}
10951098
};
10961099

tests/test-common.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@ const TEST_TYPES = {
3434
idRegex: [
3535
// terms
3636
/compact-manifest.jsonld#tp001$/,
37-
// rel iri
38-
/compact-manifest.jsonld#t0095$/,
3937
// type set
4038
/compact-manifest.jsonld#t0104$/,
4139
/compact-manifest.jsonld#t0105$/,
42-
// rel vocab
43-
/compact-manifest.jsonld#t0107$/,
4440
// @type: @none
4541
/compact-manifest.jsonld#ttn01$/,
4642
/compact-manifest.jsonld#ttn02$/,
@@ -117,14 +113,8 @@ const TEST_TYPES = {
117113
/expand-manifest.jsonld#t0102$/,
118114
// multiple graphs
119115
/expand-manifest.jsonld#t0103$/,
120-
// rel iri
121-
/expand-manifest.jsonld#t0092$/,
122116
// iris
123117
/expand-manifest.jsonld#t0109$/,
124-
// rel vocab
125-
/expand-manifest.jsonld#t0110$/,
126-
/expand-manifest.jsonld#t0111$/,
127-
/expand-manifest.jsonld#t0112$/,
128118
// terms beginning with ':'
129119
/expand-manifest.jsonld#t0117$/,
130120
/expand-manifest.jsonld#t0118$/,
@@ -460,10 +450,8 @@ const TEST_TYPES = {
460450
/toRdf-manifest.jsonld#t0132$/,
461451
// @vocab mapping
462452
/toRdf-manifest.jsonld#te075$/,
463-
// rel IRI
464-
/toRdf-manifest.jsonld#te092$/,
465453
/toRdf-manifest.jsonld#te109$/,
466-
/toRdf-manifest.jsonld#te110$/,
454+
// Invalid Statement
467455
/toRdf-manifest.jsonld#te111$/,
468456
/toRdf-manifest.jsonld#te112$/,
469457
// index maps

0 commit comments

Comments
 (0)