hardhat icon indicating copy to clipboard operation
hardhat copied to clipboard

Wrapping user config in a Proxy breaks RegExps in config

Open phated opened this issue 3 years ago • 3 comments

I'm writing a plugin where user config can be a string or RegExp (for filtering). However, when trying to use the RegExp, hardhat crashes with TypeError: RegExp.prototype.global getter called on non-RegExp object. This is because the RegExp isn't actually bound to the original object. This StackOverflow describes the problem and a potential solution.

phated avatar Dec 21 '21 21:12 phated

This issue was marked as stale because it didn't have any activity in the last 30 days. If you think it's still relevant, please leave a comment indicating so. Otherwise, it will be closed in 7 days.

github-actions[bot] avatar Jun 07 '22 20:06 github-actions[bot]

Definitely still relevant, you overzealous stalebot!

phated avatar Jun 07 '22 20:06 phated

@fvictorio

This issue was reproduced in hardhat-proxy-breaks-regexps by adding regExpField.

Fix below and tests are added in PR.

      let result = Reflect.get(target, property, receiver);
      if (result instanceof Function) {
        result = result.bind(target);
      }

Please let me know with any questions.

hiroshitashir avatar May 24 '23 00:05 hiroshitashir