Skip to content

fix(keys): accept a bare 0x prefix in isHexString - #161

Open
erhnysr wants to merge 1 commit into
agentcommercekit:mainfrom
erhnysr:fix/is-hex-string-0x-prefix
Open

fix(keys): accept a bare 0x prefix in isHexString#161
erhnysr wants to merge 1 commit into
agentcommercekit:mainfrom
erhnysr:fix/is-hex-string-0x-prefix

Conversation

@erhnysr

@erhnysr erhnysr commented Aug 16, 2026

Copy link
Copy Markdown

Problem

The JSDoc for isHexString at packages/keys/src/encoding/hex.ts:41 documents:

isHexString("0x") // true

The implementation returns false. It strips the 0x prefix and tests the remainder against /^[0-9A-Fa-f]+$/ — the + quantifier requires at least one character, so "0x" reduces to "" and fails.

Documented behaviour the code doesn't implement.

Fix

An explicit branch for the bare-prefix case, so "0x" matches the documented result.

"" deliberately stays false. The JSDoc says nothing about a bare empty string, and widening the quantifier to * would have changed that too — an undocumented behaviour change riding along with a documented fix. The explicit branch keeps the diff to exactly what the doc promises.

isHexString has no internal callers (verified by grep), so blast radius is limited to external consumers relying on the documented contract.

Tests

A case in hex.test.ts covering the bare prefix, plus one pinning "" as false so the distinction is intentional rather than incidental. Verified failing-first: before the change the "0x" case fails.

@agentcommercekit/keys — 101 tests pass. Full pnpm run check green: build 8/8, lint 0 warnings 0 errors, format clean, 29/29 tasks.

Changeset

patch for @agentcommercekit/keys, matching the bump used by comparable one-line fixes such as #116.


AI Disclosure: Written with Claude Code. It located the doc/runtime divergence and wrote the guard and tests; I reviewed the diff and can explain the change and its trade-offs.

Summary by CodeRabbit

  • Bug Fixes

    • Updated hexadecimal string validation so "0x" is recognized as a valid zero-length hexadecimal value.
    • Empty unprefixed strings remain invalid.
    • Existing validation for non-empty hexadecimal values is unchanged.
  • Tests

    • Added coverage for prefixed and unprefixed empty hexadecimal strings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b8cfb51-ff9e-4343-afe9-52330823eb98

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8fdaa and 2d74e39.

📒 Files selected for processing (3)
  • .changeset/is-hex-string-empty-body.md
  • packages/keys/src/encoding/hex.test.ts
  • packages/keys/src/encoding/hex.ts

Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review.


Walkthrough

The change updates isHexString to accept "0x" as a valid zero-length hexadecimal string while rejecting "". Tests cover both cases, and a patch changeset documents the behavior.

Changes

Hex string validation

Layer / File(s) Summary
Empty hex input validation
packages/keys/src/encoding/hex.ts, packages/keys/src/encoding/hex.test.ts, .changeset/is-hex-string-empty-body.md
isHexString accepts "0x" and rejects "". Tests cover both inputs, and the changeset records the patch update.

Estimated code review effort: 2 (Simple) | ~8 minutes

Merge Risk: ⚪ Minimal · up to 2d74e

The change makes isHexString("0x") match its documented behavior while keeping "" invalid, with focused tests and no actionable merge-blocking risk remaining after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: accepting a bare "0x" prefix in isHexString.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant