mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-02 18:47:07 -05:00 
			
		
		
		
	fix: creating tags with leading/traling slashes (#12778)
This commit is contained in:
		
							parent
							
								
									caa9b1a041
								
							
						
					
					
						commit
						96516ae4b9
					
				@ -140,6 +140,23 @@ describe(TagService.name, () => {
 | 
				
			|||||||
        parent: expect.objectContaining({ id: 'tag-parent' }),
 | 
					        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', () => {
 | 
					  describe('remove', () => {
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@ export const upsertTags = async (repository: ITagRepository, { userId, tags }: U
 | 
				
			|||||||
  const results: TagEntity[] = [];
 | 
					  const results: TagEntity[] = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (const tag of tags) {
 | 
					  for (const tag of tags) {
 | 
				
			||||||
    const parts = tag.split('/');
 | 
					    const parts = tag.split('/').filter(Boolean);
 | 
				
			||||||
    let parent: TagEntity | undefined;
 | 
					    let parent: TagEntity | undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const part of parts) {
 | 
					    for (const part of parts) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user