Merge pull request #10929 from Bouncey/fix/functionInComments

Incorrect error thrown when function is in comments
This commit is contained in:
Logan Tegman
2016-10-16 14:10:55 -07:00
committed by GitHub

View File

@ -7,6 +7,9 @@ window.common = (function(global) {
const detectFunctionCall = /function\s*?\(|function\s+\w+\s*?\(/gi; const detectFunctionCall = /function\s*?\(|function\s+\w+\s*?\(/gi;
const detectUnsafeJQ = /\$\s*?\(\s*?\$\s*?\)/gi; const detectUnsafeJQ = /\$\s*?\(\s*?\$\s*?\)/gi;
const detectUnsafeConsoleCall = /if\s\(null\)\sconsole\.log\(1\);/gi; const detectUnsafeConsoleCall = /if\s\(null\)\sconsole\.log\(1\);/gi;
const detectInComments = new RegExp(['\\/\\/.*?function.*?|',
'\\/\\*[\\s\\w\\W]*?function',
'[\\s\\w\\W]*?\\*\\/'].join(''), 'gi');
common.detectUnsafeCode$ = function detectUnsafeCode$(code) { common.detectUnsafeCode$ = function detectUnsafeCode$(code) {
const openingComments = code.match(/\/\*/gi); const openingComments = code.match(/\/\*/gi);
@ -35,7 +38,8 @@ window.common = (function(global) {
if ( if (
code.match(/function/g) && code.match(/function/g) &&
!code.match(detectFunctionCall) !code.match(detectFunctionCall) &&
!code.match(detectInComments)
) { ) {
return Observable.throw( return Observable.throw(
new Error('SyntaxError: Unsafe or unfinished function declaration') new Error('SyntaxError: Unsafe or unfinished function declaration')