fix(keys): accept a bare 0x prefix in isHexString - #161
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan includes up to 2 reviews per rolling hour; 1 remains after this review. WalkthroughThe change updates ChangesHex string validation
Estimated code review effort: 2 (Simple) | ~8 minutes Merge Risk: ⚪ Minimal · up to The change makes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Problem
The JSDoc for
isHexStringatpackages/keys/src/encoding/hex.ts:41documents:The implementation returns
false. It strips the0xprefix 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 staysfalse. 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.isHexStringhas 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.tscovering the bare prefix, plus one pinning""asfalseso the distinction is intentional rather than incidental. Verified failing-first: before the change the"0x"case fails.@agentcommercekit/keys— 101 tests pass. Fullpnpm run checkgreen: build 8/8, lint 0 warnings 0 errors, format clean, 29/29 tasks.Changeset
patchfor@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
"0x"is recognized as a valid zero-length hexadecimal value.Tests