mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Don't get normalized metadata for root containers
This commit is contained in:
@@ -185,7 +185,8 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
try {
|
||||
return await this.accessor.getMetadata(identifier);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof NotFoundHttpError) {
|
||||
// Trimming the trailing slash of a root container is undefined as there is no parent container
|
||||
if (error instanceof NotFoundHttpError && !this.identifierStrategy.isRootContainer(identifier)) {
|
||||
return this.accessor.getMetadata(
|
||||
{ path: hasSlash ? trimTrailingSlashes(identifier.path) : ensureTrailingSlash(identifier.path) },
|
||||
);
|
||||
|
||||
@@ -241,6 +241,27 @@ describe('A DataAccessorBasedStore', (): void => {
|
||||
.rejects.toThrow(`${resourceID.path} conflicts with existing path ${resourceID.path}/`);
|
||||
});
|
||||
|
||||
// As discussed in #475, trimming the trailing slash of a root container in getNormalizedMetadata
|
||||
// can result in undefined behaviour since there is no parent container.
|
||||
it('will not trim the slash of root containers since there is no parent.', async(): Promise<void> => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete accessor.data[root];
|
||||
|
||||
const mock = jest.spyOn(accessor, 'getMetadata');
|
||||
|
||||
const resourceID = { path: `${root}` };
|
||||
representation.metadata.removeAll(RDF.type);
|
||||
representation.metadata.contentType = 'text/turtle';
|
||||
representation.data = guardedStreamFrom([ `<${`${root}`}> a <coolContainer>.` ]);
|
||||
|
||||
await expect(store.setRepresentation(resourceID, representation))
|
||||
.resolves.toBeUndefined();
|
||||
expect(mock).toHaveBeenCalledTimes(1);
|
||||
expect(mock).toHaveBeenLastCalledWith(resourceID);
|
||||
|
||||
mock.mockRestore();
|
||||
});
|
||||
|
||||
it('will error if the target has a different resource type.', async(): Promise<void> => {
|
||||
const resourceID = { path: `${root}resource` };
|
||||
accessor.data[resourceID.path] = representation;
|
||||
|
||||
Reference in New Issue
Block a user