mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Code Node): Do not validate code within comments (#12938)
This commit is contained in:
51
packages/nodes-base/nodes/Code/test/JsCodeValidator.test.ts
Normal file
51
packages/nodes-base/nodes/Code/test/JsCodeValidator.test.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { validateNoDisallowedMethodsInRunForEach } from '../JsCodeValidator';
|
||||
|
||||
describe('JsCodeValidator', () => {
|
||||
describe('validateNoDisallowedMethodsInRunForEach', () => {
|
||||
it('should not throw error if disallow method is used within single line comments', () => {
|
||||
const code = [
|
||||
"// Add a new field called 'myNewField' to the JSON of the item",
|
||||
'$input.item.json.myNewField = 1;',
|
||||
' // const xxx = $input.all()',
|
||||
'return $input.item;',
|
||||
].join('\n');
|
||||
|
||||
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not throw error if disallow method is used in single multi line comments', () => {
|
||||
const code = [
|
||||
"// Add a new field called 'myNewField' to the JSON of the item",
|
||||
'$input.item.json.myNewField = 1;',
|
||||
'/** const xxx = $input.all()*/',
|
||||
'return $input.item;',
|
||||
].join('\n');
|
||||
|
||||
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should not throw error if disallow method is used within multi line comments', () => {
|
||||
const code = [
|
||||
"// Add a new field called 'myNewField' to the JSON of the item",
|
||||
'$input.item.json.myNewField = 1;',
|
||||
'/**',
|
||||
'*const xxx = $input.all()',
|
||||
'*/',
|
||||
'return $input.item;',
|
||||
].join('\n');
|
||||
|
||||
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should throw error if disallow method is used', () => {
|
||||
const code = [
|
||||
"// Add a new field called 'myNewField' to the JSON of the item",
|
||||
'$input.item.json.myNewField = 1;',
|
||||
'const xxx = $input.all()',
|
||||
'return $input.item;',
|
||||
].join('\n');
|
||||
|
||||
expect(() => validateNoDisallowedMethodsInRunForEach(code, 0)).toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user