Skip to content

Commit c3be74c

Browse files
authored
fix(server): support import paths with special chars (#14856)
1 parent 4bc2aa5 commit c3be74c

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

e2e/src/api/specs/library.e2e-spec.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,67 @@ describe('/libraries', () => {
403403
utils.removeImageFile(`${testAssetDir}/temp/folder} b/assetB.png`);
404404
});
405405

406+
const annoyingChars = [
407+
"'",
408+
'"',
409+
'`',
410+
'*',
411+
'{',
412+
'}',
413+
',',
414+
'(',
415+
')',
416+
'[',
417+
']',
418+
'?',
419+
'!',
420+
'@',
421+
'#',
422+
'$',
423+
'%',
424+
'^',
425+
'&',
426+
'=',
427+
'+',
428+
'~',
429+
'|',
430+
'<',
431+
'>',
432+
';',
433+
':',
434+
'/', // We never got backslashes to work
435+
];
436+
437+
it.each(annoyingChars)('should scan multiple import paths with %s', async (char) => {
438+
const library = await utils.createLibrary(admin.accessToken, {
439+
ownerId: admin.userId,
440+
importPaths: [`${testAssetDirInternal}/temp/folder${char}1`, `${testAssetDirInternal}/temp/folder${char}2`],
441+
});
442+
443+
utils.createImageFile(`${testAssetDir}/temp/folder${char}1/asset1.png`);
444+
utils.createImageFile(`${testAssetDir}/temp/folder${char}2/asset2.png`);
445+
446+
const { status } = await request(app)
447+
.post(`/libraries/${library.id}/scan`)
448+
.set('Authorization', `Bearer ${admin.accessToken}`)
449+
.send();
450+
expect(status).toBe(204);
451+
452+
await utils.waitForQueueFinish(admin.accessToken, 'library');
453+
454+
const { assets } = await utils.searchAssets(admin.accessToken, { libraryId: library.id });
455+
456+
expect(assets.items).toEqual(
457+
expect.arrayContaining([
458+
expect.objectContaining({ originalPath: expect.stringContaining(`folder${char}1/asset1.png`) }),
459+
expect.objectContaining({ originalPath: expect.stringContaining(`folder${char}2/asset2.png`) }),
460+
]),
461+
);
462+
463+
utils.removeImageFile(`${testAssetDir}/temp/folder${char}1/asset1.png`);
464+
utils.removeImageFile(`${testAssetDir}/temp/folder${char}2/asset2.png`);
465+
});
466+
406467
it('should reimport a modified file', async () => {
407468
const library = await utils.createLibrary(admin.accessToken, {
408469
ownerId: admin.userId,

server/src/repositories/storage.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export class StorageRepository implements IStorageRepository {
214214
}
215215

216216
private asGlob(pathToCrawl: string): string {
217-
const escapedPath = escapePath(pathToCrawl);
217+
const escapedPath = escapePath(pathToCrawl).replaceAll('"', '["]').replaceAll("'", "[']").replaceAll('`', '[`]');
218218
const extensions = `*{${mimeTypes.getSupportedFileExtensions().join(',')}}`;
219219
return `${escapedPath}/**/${extensions}`;
220220
}

0 commit comments

Comments
 (0)