mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-01 17:27:14 +02:00
fix(core): Coerce non-string node names in buildNodeIndex (#31411)
This commit is contained in:
parent
945349e89d
commit
6cf3b0b679
|
|
@ -438,6 +438,23 @@ describe('buildNodeIndex', () => {
|
|||
it('returns an empty array when nodes is missing', () => {
|
||||
expect(buildNodeIndex({ connections: {} } as unknown as WorkflowJSON)).toEqual([]);
|
||||
});
|
||||
|
||||
it('coerces non-string node names to an empty string', () => {
|
||||
const json = {
|
||||
nodes: [
|
||||
{ name: 123, type: 'x', position: [0, 0], parameters: {} },
|
||||
{ type: 'y', position: [0, 0], parameters: {} },
|
||||
{ name: null, type: 'z', position: [0, 0], parameters: {} },
|
||||
],
|
||||
connections: {},
|
||||
} as unknown as WorkflowJSON;
|
||||
|
||||
expect(buildNodeIndex(json)).toEqual([
|
||||
{ index: 0, name: '' },
|
||||
{ index: 1, name: '' },
|
||||
{ index: 2, name: '' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildErrorDetails', () => {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,12 @@ export function extractStructureIssues(error: unknown): WorkflowStructureIssue[]
|
|||
* counting entries in its own SDK-builder code.
|
||||
*/
|
||||
export function buildNodeIndex(json: WorkflowJSON): Array<{ index: number; name: string }> {
|
||||
return (json.nodes ?? []).map((node, index) => ({ index, name: node.name ?? '' }));
|
||||
// Defensively coerce: a malformed workflow may carry a non-string node name,
|
||||
// which would otherwise violate the `z.string()` output schema downstream.
|
||||
return (json.nodes ?? []).map((node, index) => ({
|
||||
index,
|
||||
name: typeof node.name === 'string' ? node.name : '',
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user