mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Use base IRI when parsing SPARQL update queries
Accept relative references in SPARQL updates
This commit is contained in:
parent
76def28a68
commit
775aaa79cd
@ -31,7 +31,7 @@ export class SparqlUpdateBodyParser extends BodyParser {
|
||||
let algebra: Algebra.Operation;
|
||||
try {
|
||||
const sparql = await readableToString(toAlgebraStream);
|
||||
algebra = translate(sparql, { quads: true });
|
||||
algebra = translate(sparql, { quads: true, baseIRI: metadata.identifier.value });
|
||||
} catch (error: unknown) {
|
||||
this.logger.warn('Could not translate SPARQL query to SPARQL algebra', { error });
|
||||
if (error instanceof Error) {
|
||||
|
@ -75,7 +75,7 @@ describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
'POST',
|
||||
{ 'content-type': 'text/turtle', 'transfer-encoding': 'chunked' },
|
||||
[ '<http://test.com/s1> <http://test.com/p1> <http://test.com/o1>.',
|
||||
'<http://test.com/s2> <http://test.com/p2> <http://test.com/o2>.' ],
|
||||
'<s2> <http://test.com/p2> <http://test.com/o2>.' ],
|
||||
);
|
||||
expect(response.statusCode).toBe(201);
|
||||
expect(response._getData()).toHaveLength(0);
|
||||
@ -89,8 +89,8 @@ describe('An integrated AuthenticatedLdpHandler', (): void => {
|
||||
requestUrl,
|
||||
'PATCH',
|
||||
{ 'content-type': 'application/sparql-update', 'transfer-encoding': 'chunked' },
|
||||
[ 'DELETE { <http://test.com/s1> <http://test.com/p1> <http://test.com/o1> }',
|
||||
'INSERT {<http://test.com/s3> <http://test.com/p3> <http://test.com/o3>}',
|
||||
[ 'DELETE { <s1> <http://test.com/p1> <http://test.com/o1> }',
|
||||
'INSERT {<s3> <http://test.com/p3> <http://test.com/o3>}',
|
||||
'WHERE {}',
|
||||
],
|
||||
);
|
||||
|
@ -61,4 +61,24 @@ describe('A SparqlUpdateBodyParser', (): void => {
|
||||
[ 'DELETE DATA { <http://test.com/s> <http://test.com/p> <http://test.com/o> }' ],
|
||||
);
|
||||
});
|
||||
|
||||
it('accepts relative references.', async(): Promise<void> => {
|
||||
input.request = streamifyArray(
|
||||
[ 'INSERT DATA { <#it> <http://test.com/p> <http://test.com/o> }' ],
|
||||
) as HttpRequest;
|
||||
input.metadata.identifier = namedNode('http://test.com/my-document.ttl');
|
||||
const result = await bodyParser.handle(input);
|
||||
expect(result.algebra.type).toBe(Algebra.types.DELETE_INSERT);
|
||||
expect((result.algebra as Algebra.DeleteInsert).insert).toBeRdfIsomorphic([ quad(
|
||||
namedNode('http://test.com/my-document.ttl#it'),
|
||||
namedNode('http://test.com/p'),
|
||||
namedNode('http://test.com/o'),
|
||||
) ]);
|
||||
expect(result.binary).toBe(true);
|
||||
expect(result.metadata).toBe(input.metadata);
|
||||
|
||||
expect(await arrayifyStream(result.data)).toEqual(
|
||||
[ 'INSERT DATA { <#it> <http://test.com/p> <http://test.com/o> }' ],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user