mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 09:36:44 +00:00
fix(core): Sanitize all non-alphanumeric characters from tool names (#18800)
This commit is contained in:
@@ -6,5 +6,5 @@ import type { INode } from './interfaces';
|
||||
*/
|
||||
export function nodeNameToToolName(nodeOrName: INode | string): string {
|
||||
const name = typeof nodeOrName === 'string' ? nodeOrName : nodeOrName.name;
|
||||
return name.replace(/[\s.?!=+#@&*()[\]{}:;,<>\/\\'"^%$_]+/g, '_');
|
||||
return name.replace(/[^a-zA-Z0-9_-]+/g, '_');
|
||||
}
|
||||
|
||||
@@ -49,6 +49,18 @@ describe('nodeNameToToolName', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test#+*()[]{}:;,<>/\\\'"%$Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace emojis with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test 😀 Node'))).toBe('Test_Node');
|
||||
});
|
||||
|
||||
it('should replace multiple emojis with underscores', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('🚀 Test 📊 Node 🎉'))).toBe('_Test_Node_');
|
||||
});
|
||||
|
||||
it('should handle complex emoji sequences', () => {
|
||||
expect(nodeNameToToolName(getNodeWithName('Test 👨💻 Node 🔥'))).toBe('Test_Node_');
|
||||
});
|
||||
|
||||
describe('when passed a string directly', () => {
|
||||
it('should replace spaces with underscores', () => {
|
||||
expect(nodeNameToToolName('Test Node')).toBe('Test_Node');
|
||||
|
||||
Reference in New Issue
Block a user