Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorrect error thrown when function is in comments
- Loading branch information
Showing
1 changed file
with
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ window.common = (function(global) { | |
const detectFunctionCall = /function\s*?\(|function\s+\w+\s*?\(/gi; | ||
const detectUnsafeJQ = /\$\s*?\(\s*?\$\s*?\)/gi; | ||
const detectUnsafeConsoleCall = /if\s\(null\)\sconsole\.log\(1\);/gi; | ||
const detectInComments = new RegExp(['\\/\\/.*?function.*?|', | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Bouncey
Author
Member
|
||
'\\/\\*[\\s\\w\\W]*?function', | ||
'[\\s\\w\\W]*?\\*\\/'].join(''), 'gi'); | ||
|
||
common.detectUnsafeCode$ = function detectUnsafeCode$(code) { | ||
const openingComments = code.match(/\/\*/gi); | ||
|
@@ -35,7 +38,8 @@ window.common = (function(global) { | |
|
||
if ( | ||
code.match(/function/g) && | ||
!code.match(detectFunctionCall) | ||
!code.match(detectFunctionCall) && | ||
!code.match(detectInComments) | ||
) { | ||
return Observable.throw( | ||
new Error('SyntaxError: Unsafe or unfinished function declaration') | ||
|
could you please explain this regex ? I tried to figure out but seems too tough for me.