Skip to content

Commit

Permalink
Allow @context in @reverse nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslabbinck committed Nov 19, 2021
1 parent 6b573c4 commit 3757e00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/JsonLdParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ export class JsonLdParser extends Transform implements RDF.Sink<EventEmitter, RD
this.parsingContext.emittedStack[depth] = true;
let handleKey = true;

// Keywords inside @reverse is not allowed
if (ContextUtil.isValidKeyword(key) && parentKey === '@reverse') {
// Keywords inside @reverse is not allowed apart from @context
if (ContextUtil.isValidKeyword(key) && parentKey === '@reverse' && key !== '@context') {
this.emit('error', new ErrorCoded(`Found the @id '${value}' inside an @reverse property`,
ERROR_CODES.INVALID_REVERSE_PROPERTY_MAP));
ERROR_CODES.INVALID_REVERSE_PROPERTY_MAP));
}

// Skip further processing if one of the parent nodes are invalid.
Expand Down
16 changes: 15 additions & 1 deletion test/JsonLdParser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,21 @@ describe('JsonLdParser', () => {
]);
});
});

describe('a reversed triple with context', () => {
it('@context is added to predicate in reverse', async () => {
const stream = streamifyString(`
{
"@id": "http://ex.org/obj1",
"@reverse": {
"@context": { "@vocab" : "https://cdn.jsdelivr.net/gh/treecg/specification@master/tree.ttl#" },
"view": {"@id": "http://ex.org/obj2" }
}
}`);
return expect(await arrayifyStream(stream.pipe(parser))).toBeRdfIsomorphic([
DF.quad(DF.namedNode('http://ex.org/obj2'), DF.namedNode('https://cdn.jsdelivr.net/gh/treecg/specification@master/tree.ttl#view'), DF.namedNode('http://ex.org/obj1')),
]);
});
});
describe('a reversed triple within a regular triple', () => {
it('with @id\'s', async () => {
const stream = streamifyString(`
Expand Down

0 comments on commit 3757e00

Please sign in to comment.