Skip to content

Commit

Permalink
fix(server): support import paths with special chars
Browse files Browse the repository at this point in the history
  • Loading branch information
etnoy committed Dec 22, 2024
1 parent 79a780e commit f7d628d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
61 changes: 61 additions & 0 deletions e2e/src/api/specs/library.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,67 @@ describe('/libraries', () => {
utils.removeImageFile(`${testAssetDir}/temp/folder} b/assetB.png`);
});

const annoyingChars = [
"'",
'"',
'`',
'*',
'{',
'}',
',',
'(',
')',
'[',
']',
'?',
'!',
'@',
'#',
'$',
'%',
'^',
'&',
'=',
'+',
'~',
'|',
'<',
'>',
';',
':',
'/', // We never got backslashes to work
];

it.each(annoyingChars)('should scan multiple import paths with %s', async (char) => {
const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
importPaths: [`${testAssetDirInternal}/temp/folder${char}1`, `${testAssetDirInternal}/temp/folder${char}2`],
});

utils.createImageFile(`${testAssetDir}/temp/folder${char}1/asset1.png`);
utils.createImageFile(`${testAssetDir}/temp/folder${char}2/asset2.png`);

const { status } = await request(app)
.post(`/libraries/${library.id}/scan`)
.set('Authorization', `Bearer ${admin.accessToken}`)
.send();
expect(status).toBe(204);

await utils.waitForQueueFinish(admin.accessToken, 'library');

const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });

expect(assets.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ originalPath: expect.stringContaining(`folder${char}1/asset1.png`) }),
expect.objectContaining({ originalPath: expect.stringContaining(`folder${char}2/asset2.png`) }),
]),
);

utils.removeImageFile(`${testAssetDir}/temp/folder${char}1/asset1.png`);
utils.removeImageFile(`${testAssetDir}/temp/folder${char}2/asset2.png`);
});

it('should reimport a modified file', async () => {
const library = await utils.createLibrary(admin.accessToken, {
ownerId: admin.userId,
Expand Down
2 changes: 1 addition & 1 deletion server/src/repositories/storage.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class StorageRepository implements IStorageRepository {
}

private asGlob(pathToCrawl: string): string {
const escapedPath = escapePath(pathToCrawl);
const escapedPath = escapePath(pathToCrawl).replaceAll('"', '["]').replaceAll("'", "[']").replaceAll('`', '[`]');
const extensions = `*{${mimeTypes.getSupportedFileExtensions().join(',')}}`;
return `${escapedPath}/**/${extensions}`;
}
Expand Down

0 comments on commit f7d628d

Please sign in to comment.