Skip to content

fix: _getBytes() regex fails for large strings #4967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adraffy
Copy link

@adraffy adraffy commented Mar 26, 2025

  • simplify hex regex

@ricmoo
Copy link
Member

ricmoo commented Mar 26, 2025

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)?

@adraffy
Copy link
Author

adraffy commented Mar 26, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants