-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Code Node): Do not validate code within comments (#12938)
- Loading branch information
1 parent
9590e5d
commit cdfa225
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/nodes-base/nodes/Code/test/JsCodeValidator.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); | ||
}); |