From 3551cdd7b2db08b1632841f819d008757d28e8e2 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 19 Feb 2024 17:38:29 +0100 Subject: [PATCH] fix: Do not rely on problematic regex Addresses #201 --- function/#/copy.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/function/#/copy.js b/function/#/copy.js index 81ae7838..897207bb 100644 --- a/function/#/copy.js +++ b/function/#/copy.js @@ -1,19 +1,20 @@ "use strict"; var mixin = require("../../object/mixin") - , validFunction = require("../valid-function") - , re = /^\s*function\s*([\0-')-\uffff]+)*\s*\(([\0-(*-\uffff]*)\)\s*\{/; + , validFunction = require("../valid-function"); module.exports = function () { - var match = String(validFunction(this)).match(re), fn; + validFunction(this); + var args = []; + for (var i = 0; i < this.length; ++i) args.push("arg" + (i + 1)); // eslint-disable-next-line no-new-func - fn = new Function( + var fn = new Function( "fn", "return function " + - match[1].trim() + + (this.name || "") + "(" + - match[2] + + args.join(", ") + ") { return fn.apply(this, arguments); };" )(this); try { mixin(fn, this); }