@@ -7,6 +7,7 @@ const {isKeyword} = require('./context');
77const graphTypes = require ( './graphTypes' ) ;
88const types = require ( './types' ) ;
99const util = require ( './util' ) ;
10+ const url = require ( './url' ) ;
1011const JsonLdError = require ( './JsonLdError' ) ;
1112const {
1213 createNodeMap : _createNodeMap ,
@@ -453,6 +454,32 @@ function _validateFrame(frame) {
453454 'Invalid JSON-LD syntax; a JSON-LD frame must be a single object.' ,
454455 'jsonld.SyntaxError' , { frame} ) ;
455456 }
457+
458+ if ( frame [ 0 ] . hasOwnProperty ( '@id' ) ) {
459+ for ( const id of util . asArray ( frame [ 0 ] [ '@id' ] ) ) {
460+ // @id must be wildcard or an IRI
461+ if ( ! ( types . isObject ( id ) || url . isAbsolute ( id ) ) ||
462+ ( types . isString ( id ) && id . indexOf ( '_:' ) === 0 ) )
463+ {
464+ throw new JsonLdError (
465+ 'Invalid JSON-LD syntax; invalid @id in frame.' ,
466+ 'jsonld.SyntaxError' , { code : 'invalid frame' , frame} ) ;
467+ }
468+ }
469+ }
470+
471+ if ( frame [ 0 ] . hasOwnProperty ( '@type' ) ) {
472+ for ( const type of util . asArray ( frame [ 0 ] [ '@type' ] ) ) {
473+ // @id must be wildcard or an IRI
474+ if ( ! ( types . isObject ( type ) || url . isAbsolute ( type ) ) ||
475+ ( types . isString ( type ) && type . indexOf ( '_:' ) === 0 ) )
476+ {
477+ throw new JsonLdError (
478+ 'Invalid JSON-LD syntax; invalid @type in frame.' ,
479+ 'jsonld.SyntaxError' , { code : 'invalid frame' , frame} ) ;
480+ }
481+ }
482+ }
456483}
457484
458485/**
@@ -733,7 +760,7 @@ function _cleanupPreserve(input, options) {
733760 }
734761 }
735762 return input ;
736- } ;
763+ }
737764
738765/**
739766 * Adds framing output to the given parent.
0 commit comments