ethers.js
ethers.js copied to clipboard
fix: `_getBytes()` regex fails for large strings
- simplify hex regex
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)?
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.