mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 10:31:15 +00:00
refactor: Simplify resolveIcon checks and add tests (#11165)
This commit is contained in:
@@ -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[] {
|
||||
|
||||
Reference in New Issue
Block a user