mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(Rename Keys Node): Add a warning for regex that affect performance (#18911)
This commit is contained in:
@@ -331,6 +331,20 @@ export class NodeTestHarness {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const msg = `Equality failed for "${testData.description}" at node "${nodeName}"`;
|
const msg = `Equality failed for "${testData.description}" at node "${nodeName}"`;
|
||||||
|
// When continue on fail is on the json wrapper is removed for some reason
|
||||||
|
const runs = output.nodeData[nodeName];
|
||||||
|
if (Array.isArray(runs)) {
|
||||||
|
for (let runIndex = 0; runIndex < runs.length; runIndex++) {
|
||||||
|
const run = runs[runIndex];
|
||||||
|
if (!Array.isArray(run)) continue;
|
||||||
|
for (let itemIndex = 0; itemIndex < run.length; itemIndex++) {
|
||||||
|
const original = run[itemIndex];
|
||||||
|
if (original && !original.json) {
|
||||||
|
run[itemIndex] = { json: { ...original } };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
expect(resultData, msg).toEqual(output.nodeData[nodeName]);
|
expect(resultData, msg).toEqual(output.nodeData[nodeName]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
|
||||||
|
|
||||||
|
describe('Test DebugHelper Node', () => {
|
||||||
|
new NodeTestHarness().setupTests();
|
||||||
|
});
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"type": "n8n-nodes-base.manualTrigger",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [-448, 192],
|
||||||
|
"id": "9f62b838-ecbe-4012-8026-9e3d48669c49",
|
||||||
|
"name": "When clicking ‘Execute workflow’"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"type": "n8n-nodes-base.debugHelper",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [-224, 192],
|
||||||
|
"id": "7d381110-e62e-4911-8527-e6265fe4be11",
|
||||||
|
"name": "DebugHelper",
|
||||||
|
"onError": "continueErrorOutput"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"parameters": {},
|
||||||
|
"type": "n8n-nodes-base.noOp",
|
||||||
|
"typeVersion": 1,
|
||||||
|
"position": [0, 192],
|
||||||
|
"id": "0a6ef4ec-3876-4d99-998e-9ba26ca474b5",
|
||||||
|
"name": "No Operation, do nothing"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": {
|
||||||
|
"When clicking ‘Execute workflow’": {
|
||||||
|
"main": [
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": "DebugHelper",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"DebugHelper": {
|
||||||
|
"main": [
|
||||||
|
[],
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"node": "No Operation, do nothing",
|
||||||
|
"type": "main",
|
||||||
|
"index": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pinData": {
|
||||||
|
"No Operation, do nothing": [
|
||||||
|
{
|
||||||
|
"error": "Node has thrown an error"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meta": {
|
||||||
|
"instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import type {
|
|||||||
INodeType,
|
INodeType,
|
||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
interface IRenameKey {
|
interface IRenameKey {
|
||||||
currentKey: string;
|
currentKey: string;
|
||||||
newKey: string;
|
newKey: string;
|
||||||
@@ -81,7 +80,7 @@ export class RenameKeys implements INodeType {
|
|||||||
displayName: 'Regex',
|
displayName: 'Regex',
|
||||||
name: 'regexReplacement',
|
name: 'regexReplacement',
|
||||||
placeholder: 'Add new regular expression',
|
placeholder: 'Add new regular expression',
|
||||||
description: 'Adds a regular expressiond',
|
description: 'Adds a regular expression',
|
||||||
type: 'fixedCollection',
|
type: 'fixedCollection',
|
||||||
typeOptions: {
|
typeOptions: {
|
||||||
multipleValues: true,
|
multipleValues: true,
|
||||||
@@ -149,11 +148,21 @@ export class RenameKeys implements INodeType {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
hints: [
|
||||||
|
{
|
||||||
|
type: 'warning',
|
||||||
|
message:
|
||||||
|
'Complex regex patterns like nested quantifiers .*+, ()*+, or multiple wildcards may cause performance issues. Consider using simpler patterns like [a-z]+ or \\w+ for better performance.',
|
||||||
|
displayCondition:
|
||||||
|
'={{ $parameter.additionalOptions.regexReplacement.replacements && $parameter.additionalOptions.regexReplacement.replacements.some(r => r.searchRegex && /(\\.\\*\\+|\\)\\*\\+|\\+\\*|\\*.*\\*|\\+.*\\+|\\?.*\\?|\\{[0-9]+,\\}|\\*{2,}|\\+{2,}|\\?{2,}|[a-zA-Z0-9]{4,}[\\*\\+]|\\([^)]*\\|[^)]*\\)[\\*\\+])/.test(r.searchRegex)) }}',
|
||||||
|
whenToDisplay: 'always',
|
||||||
|
location: 'outputPane',
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
|
|
||||||
const returnData: INodeExecutionData[] = [];
|
const returnData: INodeExecutionData[] = [];
|
||||||
|
|
||||||
let item: INodeExecutionData;
|
let item: INodeExecutionData;
|
||||||
@@ -208,6 +217,7 @@ export class RenameKeys implements INodeType {
|
|||||||
newItem.json = renameObjectKeys(newItem.json, depth as number);
|
newItem.json = renameObjectKeys(newItem.json, depth as number);
|
||||||
};
|
};
|
||||||
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
|
||||||
|
try {
|
||||||
renameKeys = this.getNodeParameter('keys.key', itemIndex, []) as IRenameKey[];
|
renameKeys = this.getNodeParameter('keys.key', itemIndex, []) as IRenameKey[];
|
||||||
const regexReplacements = this.getNodeParameter(
|
const regexReplacements = this.getNodeParameter(
|
||||||
'additionalOptions.regexReplacement.replacements',
|
'additionalOptions.regexReplacement.replacements',
|
||||||
@@ -236,6 +246,17 @@ export class RenameKeys implements INodeType {
|
|||||||
regexReplacements.forEach(regexReplaceKey);
|
regexReplacements.forEach(regexReplaceKey);
|
||||||
|
|
||||||
returnData.push(newItem);
|
returnData.push(newItem);
|
||||||
|
} catch (error) {
|
||||||
|
if (this.continueOnFail()) {
|
||||||
|
const executionErrorData = this.helpers.constructExecutionMetaData(
|
||||||
|
this.helpers.returnJsonArray({ error: error.message }),
|
||||||
|
{ itemData: { item: itemIndex } },
|
||||||
|
);
|
||||||
|
returnData.push(...executionErrorData);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [returnData];
|
return [returnData];
|
||||||
|
|||||||
Reference in New Issue
Block a user