@@ -312,18 +312,19 @@ Tried mapping ${key} to ${JSON.stringify(keyValue)}`, ERROR_CODES.INVALID_KEYWOR
312
312
expandOptions : IExpandOptions ,
313
313
/* istanbul ignore next */
314
314
keys = Object . keys ( contextAfter ) ) {
315
- for ( const key of Object . keys ( contextAfter ) ) {
315
+ for ( const key of keys ) {
316
316
if ( Util . isTermProtected ( contextBefore , key ) ) {
317
317
// The entry in the context before will always be in object-mode
318
318
// If the new entry is in string-mode, convert it to object-mode
319
319
// before checking if it is identical.
320
320
if ( typeof contextAfter [ key ] === 'string' ) {
321
- contextAfter [ key ] = { '@id' : contextAfter [ key ] } ;
322
- }
321
+ contextAfter [ key ] = { '@id' : contextAfter [ key ] , '@protected' : true } ;
322
+ } else {
323
323
// We modify this deliberately,
324
324
// as we need it for the value comparison (they must be identical modulo '@protected')),
325
325
// and for the fact that this new value will override the first one.
326
- contextAfter [ key ] = { ...contextAfter [ key ] , '@protected' : true } ;
326
+ contextAfter [ key ] = { ...contextAfter [ key ] , '@protected' : true } ;
327
+ }
327
328
328
329
// Error if they are not identical
329
330
if ( ! deepEqual ( contextBefore [ key ] , contextAfter [ key ] ) ) {
@@ -794,10 +795,14 @@ must be one of ${Util.CONTAINERS.join(', ')}`, ERROR_CODES.INVALID_CONTAINER_MAP
794
795
this . applyScopedProtected ( newContext , { processingMode } , defaultExpandOptions ) ;
795
796
796
797
const keys = Object . keys ( newContext ) ;
798
+
799
+ const overlappingKeys : string [ ] = [ ] ;
797
800
if ( typeof parentContext === 'object' ) {
798
801
// Merge different parts of the final context in order
799
802
for ( const key in parentContext ) {
800
- if ( ! ( key in newContext ) ) {
803
+ if ( key in newContext ) {
804
+ overlappingKeys . push ( key ) ;
805
+ } else {
801
806
newContext [ key ] = parentContext [ key ] ;
802
807
}
803
808
}
@@ -825,7 +830,7 @@ must be one of ${Util.CONTAINERS.join(', ')}`, ERROR_CODES.INVALID_CONTAINER_MAP
825
830
826
831
// In JSON-LD 1.1, check if we are not redefining any protected keywords
827
832
if ( ! ignoreProtection && parentContext && processingMode >= 1.1 ) {
828
- this . validateKeywordRedefinitions ( parentContext , newContext , defaultExpandOptions , keys ) ;
833
+ this . validateKeywordRedefinitions ( parentContext , newContext , defaultExpandOptions , overlappingKeys ) ;
829
834
}
830
835
831
836
if ( this . validateContext && ! ioptions . skipValidation ) {
0 commit comments