Skip to content

Commit ed79ad7

Browse files
gkelloggdavidlehn
authored andcommitted
Check for invalid values of @embed.
1 parent 05ce5aa commit ed79ad7

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
- Support for RDF transformation of `@direction` when `rdfDirection` is
3636
'i18n-datatype'.
3737
- Top level `@graph` omitted if `omitGraph` is `true`.
38+
- Check for invalid values of `@embed`.
3839

3940
## 2.0.2 - 2020-01-17
4041

lib/frame.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ api.frame = (state, subjects, frame, parent, property = null) => {
118118
}
119119
state.link[id] = output;
120120

121+
// validate @embed
122+
if((flags.embed === '@first' || flags.embed === '@last') && state.is11) {
123+
throw new JsonLdError(
124+
'Invalid JSON-LD syntax; invalid value of @embed.',
125+
'jsonld.SyntaxError', {code: 'invalid @embed value', frame: frame});
126+
}
127+
121128
// if embed is @never or if a circular reference would be created by an
122129
// embed, the subject cannot be embedded, just add the reference;
123130
// note that a circular reference won't occur when the embed flag is
@@ -346,11 +353,15 @@ function _getFrameFlag(frame, options, name) {
346353
// true => "@last"
347354
// false => "@never"
348355
if(rval === true) {
349-
rval = '@last';
356+
rval = '@once';
350357
} else if(rval === false) {
351358
rval = '@never';
352-
} else if(rval !== '@always' && rval !== '@never' && rval !== '@link') {
353-
rval = '@last';
359+
} else if(rval !== '@always' && rval !== '@never' && rval !== '@link' &&
360+
rval !== '@first' && rval !== '@last' && rval !== '@once')
361+
{
362+
throw new JsonLdError(
363+
'Invalid JSON-LD syntax; invalid value of @embed.',
364+
'jsonld.SyntaxError', {code: 'invalid @embed value', frame: frame});
354365
}
355366
}
356367
return rval;

lib/jsonld.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,6 @@ jsonld.frame = async function(input, frame, options) {
475475
if(!options.hasOwnProperty('pruneBlankNodeIdentifiers')) {
476476
options.pruneBlankNodeIdentifiers = _processingMode(activeCtx, 1.1);
477477
}
478-
if((options.embed === '@first' || options.embed === '@last') &&
479-
_processingMode(activeCtx, 1.1))
480-
{
481-
console.warn(`WARNING: ${options.embed} is not a valid value ` +
482-
`of @embed in 1.1 mode.`);
483-
}
484478

485479
// expand input
486480
const expanded = await jsonld.expand(input, options);
@@ -496,6 +490,8 @@ jsonld.frame = async function(input, frame, options) {
496490
const frameKeys = Object.keys(frame)
497491
.map(key => _expandIri(activeCtx, key, {vocab: true}));
498492
opts.merged = !frameKeys.includes('@graph');
493+
opts.is11 = _processingMode(activeCtx, 1.1);
494+
499495
// do framing
500496
const framed = _frameMergedOrDefault(expanded, expandedFrame, opts);
501497

tests/test-common.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ const TEST_TYPES = {
170170
// blank nodes
171171
/frame-manifest.jsonld#t0052$/,
172172
/frame-manifest.jsonld#t0053$/,
173-
// embed
174-
/frame-manifest.jsonld#t0054$/,
175173
// lists
176174
/frame-manifest.jsonld#t0055$/,
177175
/frame-manifest.jsonld#t0058$/,

0 commit comments

Comments
 (0)