Skip to content

isHex shouldn't accept odd number of nibbles #5048

Description

@CodeSandwich

Check existing issues

Viem Version

2.48.1

Current Behavior

'isHex' accepts odd numbered nibbles, even in the strict mode, isHex("0x1") === true.

Expected Behavior

'isHex' rejects odd numbered nibbles in the scrict mode, isHex(0x1) === false.

Steps To Reproduce

No response

Link to Minimal Reproducible Example

No response

Anything else?

It really doesn't make sense to accept odd-length hex values.

Everything around EVM works with full bytes and never with half-bytes. I'm not aware of any API or tool that would accept odd-length hex values, they all reject such hex strings as malformed with the risk of weirder ones silently corrupting data by "fixing" the parity. There's no use case for handling odd-length hex values, but there are risks in accepting them as valid.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions