mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
fix: creating tags with leading/traling slashes (#12778)
This commit is contained in:
parent
caa9b1a041
commit
96516ae4b9
2 changed files with 18 additions and 1 deletions
|
@ -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', () => {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue