Skip to content

Commit f8e0697

Browse files
authored
Fix containers handling for imported contexts, Closes #40
1 parent 5eb54d0 commit f8e0697

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/ContextParser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ must be one of ${Util.CONTAINERS.join(', ')}`, ERROR_CODES.INVALID_CONTAINER_MAP
880880
ERROR_CODES.INVALID_CONTEXT_ENTRY);
881881
}
882882

883+
// Containers have to be converted into hash values the same way as for the importing context
884+
// Otherwise context validation will fail for container values
885+
this.containersToHash(importContext);
883886
return importContext;
884887
}
885888

test/ContextParser-test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,20 @@ Tried mapping @id to {}`, ERROR_CODES.KEYWORD_REDEFINITION));
31813181
}, { processingMode: 1.0 })).rejects.toThrow(new ErrorCoded('Context importing is not supported in JSON-LD 1.0',
31823182
ERROR_CODES.INVALID_CONTEXT_ENTRY));
31833183
});
3184+
3185+
it('should convert containers to hash values after loading context', async () => {
3186+
const parsed = await parser.loadImportContext('http://example.org/simple_with_container.jsonld');
3187+
3188+
expect(parsed).toEqual({
3189+
rdfs: "https://www.w3.org/2000/01/rdf-schema#",
3190+
label: {
3191+
"@id": "rdfs:label",
3192+
"@container": {
3193+
"@language": true,
3194+
},
3195+
},
3196+
});
3197+
});
31843198
});
31853199

31863200
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"@context":
3+
{
4+
"rdfs": "https://www.w3.org/2000/01/rdf-schema#",
5+
"label": {
6+
"@id": "rdfs:label",
7+
"@container": "@language"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)