From d5c3731536847d65aa76f3a344af40c4c17ecde3 Mon Sep 17 00:00:00 2001 From: Stuart Taylor Date: Mon, 26 Sep 2016 22:19:33 +0100 Subject: [PATCH] Incorrect error thrown when function is in comments --- client/commonFramework/detect-unsafe-code-stream.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/commonFramework/detect-unsafe-code-stream.js b/client/commonFramework/detect-unsafe-code-stream.js index 14ed08f77b..8cf7116622 100644 --- a/client/commonFramework/detect-unsafe-code-stream.js +++ b/client/commonFramework/detect-unsafe-code-stream.js @@ -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.*?|', + '\\/\\*[\\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')