Skip to content

Commit 84b7768

Browse files
gkelloggdavidlehn
authored andcommitted
Check unused scoped contexts for validity.
1 parent 4eadf04 commit 84b7768

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Better frame validation.
2222
- Wildcard matching on `@id` and other `requireAll` semantics.
2323
- Default frame for lists.
24+
- Check unused scoped contexts for validity.
2425

2526
### Changed
2627
- Keep term definitions mapping to null so they may be protected.

lib/context.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,27 @@ api.process = async ({
353353
options,
354354
overrideProtected
355355
});
356+
357+
if(_isObject(ctx[key]) && '@context' in ctx[key]) {
358+
// parse context to validate
359+
try {
360+
await api.process({
361+
activeCtx: rval,
362+
localCtx: ctx[key]['@context'],
363+
overrideProtected: true,
364+
options
365+
});
366+
} catch(e) {
367+
throw new JsonLdError(
368+
'Invalid JSON-LD syntax; invalid scoped context.',
369+
'jsonld.SyntaxError',
370+
{
371+
code: 'invalid scoped context',
372+
context: ctx[key]['@context'],
373+
term: key
374+
});
375+
}
376+
}
356377
}
357378

358379
// cache processed result

tests/test-common.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ const TEST_TYPES = {
8585
/expand-manifest.jsonld#thc05$/,
8686
// remote
8787
/remote-doc-manifest.jsonld#t0013$/, // HTML
88-
// unused scoped context
89-
/expand-manifest.jsonld#tc032$/,
90-
/expand-manifest.jsonld#tc033$/,
9188
]
9289
},
9390
fn: 'expand',
@@ -206,9 +203,6 @@ const TEST_TYPES = {
206203
// direction (compound-literal)
207204
/toRdf-manifest.jsonld#tdi11$/,
208205
/toRdf-manifest.jsonld#tdi12$/,
209-
// unused scoped context
210-
/toRdf-manifest.jsonld#tc032$/,
211-
/toRdf-manifest.jsonld#tc033$/,
212206
]
213207
},
214208
fn: 'toRDF',

0 commit comments

Comments
 (0)