Skip to content

fix(platform-js): correct hex parse error messages for mixed valid/invalid chars#108

Open
Mechack08 wants to merge 1 commit intomidnightntwrk:mainfrom
Mechack08:fix/hex-parsing-error-messages
Open

fix(platform-js): correct hex parse error messages for mixed valid/invalid chars#108
Mechack08 wants to merge 1 commit intomidnightntwrk:mainfrom
Mechack08:fix/hex-parsing-error-messages

Conversation

@Mechack08
Copy link
Copy Markdown

Summary

parseHex() in platform-js/src/effect/internal/hex.ts had two bugs in error
reporting when incompleteChars contained a mix of valid and invalid hex chars.

Bug 1 - Wrong error type (odd-length incompleteChars)

parseHex('abX') was reporting "Last byte incomplete" instead of
"Invalid hex-digit 'X' at index 2".

Bug 2 - Wrong character position (even-length incompleteChars)

parseHex('0xaG') was pointing to 'a' at index 2 instead of 'G' at index 3.

Fix

Scan incompleteChars character by character to find the first non-hex digit.
Fall through to the "incomplete byte" error only when every char in
incompleteChars is a valid hex digit.

Tests Added

File Before After
Hex.test.ts 7 10 (+3 regression cases)
DomainSeparator.test.ts 0 (new file) 7
SigningKey.test.ts 0 (new file) 8
NetworkId.test.ts 4 14 (+make/equals/isNetworkId/toString/toJSON)

Total platform-js test count: 35 → 63, all passing.

…valid chars

The parseHex function in internal/hex.ts had two related bugs when
incompleteChars contained a mix of valid and invalid hex characters:

1. When incompleteChars.length was odd, the function unconditionally
   reported "Last byte is incomplete" — even when the first problematic
   character was not a valid hex digit (e.g. 'abX' reported incomplete
   instead of 'Invalid hex-digit X at index 2').

2. When incompleteChars.length was even, the function always reported
   source[byteChars.length + offset] as the invalid character — but
   this pointed to the first character of incompleteChars, which could
   itself be a valid hex digit if the real invalid char appeared later
   (e.g. '0xaG' reported 'a' as the bad char instead of 'G').

Fix: scan incompleteChars character by character to find the first
non-hex-digit and report its absolute position. Fall through to
The parseHex function in internal/hex.ts had two related bugs when
incompleteChars contained a mix of valid and invalid hex characters:

1. Wh coincompleteChars contained a mix of valid and invalid hex charactemp
1. When incompleteChars.length was odd, the function unconditionaln-l   reported "Last byte is incomplete" — even when the first proil   character was not a valid hex digit (e.g. 'abX' reported incomplete
   g.   instead of 'Invalid hex-digit X at index 2').

2. When incompleteCor
2. When incompleteChars.length was even, the f ex   source[byteChars.length + offset] as the invalid character — , is   this pointed to thend toJSON.
@Mechack08 Mechack08 requested a review from a team as a code owner March 23, 2026 09:40
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