ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

fix: `_getBytes()` regex fails for large strings

Open adraffy opened this issue 9 months ago • 2 comments

  • simplify hex regex

adraffy avatar Mar 26 '25 06:03 adraffy

Interesting. Is it the non-capturing matching group that causes it to fail or the matching group in general?

Can you provide an example string (or just a length) for which the function fails? And the environment (browser vs node)?

ricmoo avatar Mar 26 '25 06:03 ricmoo

Seems okay in node but:

$ bun --version
1.2.4
$ bun repl
> require('ethers').getBytes('0x'.padEnd(86014, '0'))
> require('ethers').getBytes('0x'.padEnd(86016, '0')) // error: invalid BytesLike value

It seems fixed now on 1.2.6?


It's still probably worth it to make the change:

  • !!'0x'.padEnd(3000000, '0').match(/^0x(?:[0-9a-f][0-9a-f])*$/i)false
  • !!'0x'.padEnd(3000000, '0').match(/^0x[0-9a-f]*$/)true
  • !!'0x'.padEnd(1000000000, '0').match(/^0x[0-9a-f]*$/)true

I encountered it parsing blobs.

adraffy avatar Mar 26 '25 19:03 adraffy