From 70ce2ba0d64ac3f203174c845ef2e5e56aefaba2 Mon Sep 17 00:00:00 2001
From: Daniel Di Sarli <danieleds@users.noreply.github.com>
Date: Thu, 14 Sep 2017 16:11:58 +0200
Subject: [PATCH] Fix crash with minified functions

This is an example of a valid minified function that doesn't work with the regex in toFunction:

    function profileModelWorkerRunner(){var Moment=eval("require")("moment-timezone");self.onmessage=function(event){var profileModelClass=eval("require")(event.data.profileModelPath).default,profileModelWorker=new profileModelClass(Moment,event.data.timezone),params=event.data.params;var result=profileModelWorker.check(params);postMessage(result)}}

I've replaced that code with an eval, which is safer than parsing JS code (which is not a context-free grammar) with regular expressions.
---
 src/worker.js | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/worker.js b/src/worker.js
index 907f620..d76e761 100644
--- a/src/worker.js
+++ b/src/worker.js
@@ -13,10 +13,10 @@ function explode (arg) {
 }
 
 function toFunction (arg) {
-	const args = trim(arg.replace(/^.*\(/, "").replace(/[\t|\r|\n|\"|\']+/g, "").replace(/\).*/, "")),
-		body = trim(arg.replace(/^.*\{/, "").replace(/\}$/, ""));
+	var __worker_evaluated_function_ = null;
+	eval('__worker_evaluated_function_ = (' + arg + ')')
 
-	return Function.apply(Function, explode(args).concat([body]));
+	return __worker_evaluated_function_;
 }
 
 // Bootstraps the Worker
-- 
GitLab