Skip to content
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

Is the pattern for "hex encoded 256 bit unsigned integer" correct? #556

Open
fvictorio opened this issue Jun 13, 2024 · 1 comment · May be fixed by #605
Open

Is the pattern for "hex encoded 256 bit unsigned integer" correct? #556

fvictorio opened this issue Jun 13, 2024 · 1 comment · May be fixed by #605

Comments

@fvictorio
Copy link

The pattern for hex encoded 256 bit unsigned integer doesn't look correct to me:

^0x([1-9a-f]+[0-9a-f]{0,31})|0$

I think there are two problems here. The first one is that the + there means that one million 1s would be a valid value, which is obviously incorrect.

And if the + is removed, there's still a problem, because then the string has a length of at most 32 hex characters, but for a 32-byte value the max length should be 64 hex characters.

I think the right pattern should be:

^0x([1-9a-f][0-9a-f]{0,63})|0$

I don't know why the test for this works fine though. I haven't checked how these tests are executed, and if they validate the patterns somehow.

@PelleKrab
Copy link

PelleKrab commented Oct 29, 2024

Should '|0' be in the parenthesis as well? Otherwise ''anything0" is valid.

^(0x([1-9a-f][0-9a-f]{0,63}|0)|0)$ // '0' = true

or

^0x([1-9a-f][0-9a-f]{0,63}|0)$ // '0' = false

@PelleKrab PelleKrab linked a pull request Nov 27, 2024 that will close this issue
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 a pull request may close this issue.

2 participants