mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Prevent setRepresentation crash if there is no root container
This commit is contained in:
parent
c05933f652
commit
6424b07fc6
@ -385,7 +385,9 @@ export class DataAccessorBasedStore implements ResourceStore {
|
|||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (NotFoundHttpError.isInstance(error)) {
|
if (NotFoundHttpError.isInstance(error)) {
|
||||||
// Make sure the parent exists first
|
// Make sure the parent exists first
|
||||||
await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(container));
|
if (!this.identifierStrategy.isRootContainer(container)) {
|
||||||
|
await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(container));
|
||||||
|
}
|
||||||
await this.writeData(container, new BasicRepresentation([], container), true);
|
await this.writeData(container, new BasicRepresentation([], container), true);
|
||||||
} else {
|
} else {
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -305,6 +305,14 @@ describe('A DataAccessorBasedStore', (): void => {
|
|||||||
expect(accessor.data[resourceID.path].metadata.contentType).toBeUndefined();
|
expect(accessor.data[resourceID.path].metadata.contentType).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can write resources even if root does not exist.', async(): Promise<void> => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||||
|
delete accessor.data[root];
|
||||||
|
const resourceID = { path: `${root}resource` };
|
||||||
|
await expect(store.setRepresentation(resourceID, representation)).resolves.toBeUndefined();
|
||||||
|
await expect(arrayifyStream(accessor.data[resourceID.path].data)).resolves.toEqual([ resourceData ]);
|
||||||
|
});
|
||||||
|
|
||||||
it('can write containers with quad data.', async(): Promise<void> => {
|
it('can write containers with quad data.', async(): Promise<void> => {
|
||||||
const resourceID = { path: `${root}container/` };
|
const resourceID = { path: `${root}container/` };
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user