1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00

fix: creating tags with leading/traling slashes (#12778)

This commit is contained in:
Daniel Dietzler 2024-09-18 21:25:13 +02:00 committed by GitHub
parent caa9b1a041
commit 96516ae4b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 1 deletions

View file

@ -140,6 +140,23 @@ describe(TagService.name, () => {
parent: expect.objectContaining({ id: 'tag-parent' }),
});
});
it('should upsert a tag and ignore leading and trailing slashes', async () => {
tagMock.getByValue.mockResolvedValueOnce(null);
tagMock.upsertValue.mockResolvedValueOnce(tagStub.parent);
tagMock.upsertValue.mockResolvedValueOnce(tagStub.child);
await expect(sut.upsert(authStub.admin, { tags: ['/Parent/Child/'] })).resolves.toBeDefined();
expect(tagMock.upsertValue).toHaveBeenNthCalledWith(1, {
value: 'Parent',
userId: 'admin_id',
parent: undefined,
});
expect(tagMock.upsertValue).toHaveBeenNthCalledWith(2, {
value: 'Parent/Child',
userId: 'admin_id',
parent: expect.objectContaining({ id: 'tag-parent' }),
});
});
});
describe('remove', () => {

View file

@ -8,7 +8,7 @@ export const upsertTags = async (repository: ITagRepository, { userId, tags }: U
const results: TagEntity[] = [];
for (const tag of tags) {
const parts = tag.split('/');
const parts = tag.split('/').filter(Boolean);
let parent: TagEntity | undefined;
for (const part of parts) {