Skip to content

Commit

Permalink
fix: Do not rely on problematic regex
Browse files Browse the repository at this point in the history
Addresses #201
  • Loading branch information
medikoo committed Feb 19, 2024
1 parent 7855319 commit 3551cdd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions function/#/copy.js
Original file line number Diff line number Diff line change
@@ -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); }
Expand Down

0 comments on commit 3551cdd

Please sign in to comment.