fix(core): Sanitize all non-alphanumeric characters from tool names (#18800)

This commit is contained in:
jeanpaul
2025-08-26 14:00:54 +02:00
committed by GitHub
parent df9521ff8e
commit b73f2393b4
2 changed files with 13 additions and 1 deletions

View File

@@ -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, '_');
}

View File

@@ -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');