refactor: Simplify resolveIcon checks and add tests (#11165)

This commit is contained in:
Tomi Turtiainen
2024-10-08 17:04:45 +03:00
committed by GitHub
parent ad4cb0ea0c
commit d4afb0f38b
2 changed files with 44 additions and 7 deletions

View File

@@ -29,6 +29,7 @@ import {
inE2ETests,
} from '@/constants';
import { Logger } from '@/logging/logger.service';
import { isContainedWithin } from '@/utils/path-util';
interface LoadedNodesAndCredentials {
nodes: INodeTypeData;
@@ -155,14 +156,13 @@ export class LoadNodesAndCredentials {
resolveIcon(packageName: string, url: string): string | undefined {
const loader = this.loaders[packageName];
if (loader) {
const pathPrefix = `/icons/${packageName}/`;
const filePath = path.resolve(loader.directory, url.substring(pathPrefix.length));
if (!path.relative(loader.directory, filePath).includes('..')) {
return filePath;
}
if (!loader) {
return undefined;
}
return undefined;
const pathPrefix = `/icons/${packageName}/`;
const filePath = path.resolve(loader.directory, url.substring(pathPrefix.length));
return isContainedWithin(loader.directory, filePath) ? filePath : undefined;
}
getCustomDirectories(): string[] {