fix(TheHiveProject Node): Normalize analyzers when expression returns a string (#31580)

This commit is contained in:
Hammad Khan 2026-06-03 20:06:28 +05:00 committed by GitHub
parent 9cb9a1fc46
commit 43d32fd28f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import type {
import { updateDisplayOptions, wrapData } from '@utils/utilities';
import { observableRLC, observableTypeOptions } from '../../descriptions';
import { parseAnalyzers } from '../../helpers/utils';
import { theHiveApiRequest } from '../../transport';
const properties: INodeProperties[] = [
@ -49,13 +50,7 @@ export async function execute(this: IExecuteFunctions, i: number): Promise<INode
extractValue: true,
}) as string;
const analyzers = (this.getNodeParameter('analyzers', i) as string[]).map((analyzer) => {
const parts = analyzer.split('::');
return {
analyzerId: parts[0],
cortexId: parts[1],
};
});
const analyzers = parseAnalyzers(this.getNodeParameter('analyzers', i) as string | string[]);
let response: any;
let body: IDataObject;

View File

@ -12,6 +12,18 @@ export function splitAndTrim(str: string | string[]) {
return str;
}
// The "Analyzers" field is a multiOptions parameter, so it normally resolves to
// an array of "analyzerId::cortexId" entries. When its value comes from an
// expression wrapped in surrounding text/whitespace, n8n switches to string
// interpolation and the array is coerced to a comma-joined string. Normalize
// both shapes so the operation does not throw "(...).map is not a function".
export function parseAnalyzers(value: string | string[]) {
return splitAndTrim(value).map((analyzer) => {
const [analyzerId, cortexId] = analyzer.split('::');
return { analyzerId, cortexId };
});
}
export function fixFieldType(fields: IDataObject) {
const returnData: IDataObject = {};

View File

@ -1,4 +1,10 @@
import { splitAndTrim, fixFieldType, prepareInputItem, constructFilter } from '../helpers/utils';
import {
splitAndTrim,
parseAnalyzers,
fixFieldType,
prepareInputItem,
constructFilter,
} from '../helpers/utils';
describe('Test TheHiveProject, splitAndTrim', () => {
it('should split and trim string, removing empty entries', () => {
@ -18,6 +24,49 @@ describe('Test TheHiveProject, splitAndTrim', () => {
});
});
describe('Test TheHiveProject, parseAnalyzers', () => {
it('should map an array of "analyzerId::cortexId" entries', () => {
const data = ['analyzer-1::cortex-1', 'analyzer-2::cortex-2'];
const result = parseAnalyzers(data);
expect(result).toEqual([
{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' },
{ analyzerId: 'analyzer-2', cortexId: 'cortex-2' },
]);
});
it('should map a comma-joined string (expression coercion case)', () => {
const data = 'analyzer-1::cortex-1, analyzer-2::cortex-2';
const result = parseAnalyzers(data);
expect(result).toEqual([
{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' },
{ analyzerId: 'analyzer-2', cortexId: 'cortex-2' },
]);
});
it('should handle a single analyzer provided as a string', () => {
const result = parseAnalyzers('analyzer-1::cortex-1');
expect(result).toEqual([{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' }]);
});
it('should drop empty entries from a comma-joined string', () => {
const result = parseAnalyzers('analyzer-1::cortex-1,, analyzer-2::cortex-2,');
expect(result).toEqual([
{ analyzerId: 'analyzer-1', cortexId: 'cortex-1' },
{ analyzerId: 'analyzer-2', cortexId: 'cortex-2' },
]);
});
it('should return an empty array for an empty string', () => {
expect(parseAnalyzers('')).toEqual([]);
});
});
describe('Test TheHiveProject, fixFieldType', () => {
it('should split and trim tags', () => {
const data = {