fix(platform-js): correct hex parse error messages for mixed valid/invalid chars#108
Open
Mechack08 wants to merge 1 commit intomidnightntwrk:mainfrom
Open
fix(platform-js): correct hex parse error messages for mixed valid/invalid chars#108Mechack08 wants to merge 1 commit intomidnightntwrk:mainfrom
Mechack08 wants to merge 1 commit intomidnightntwrk:mainfrom
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parseHex()inplatform-js/src/effect/internal/hex.tshad two bugs in errorreporting when
incompleteCharscontained 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
incompleteCharscharacter by character to find the first non-hex digit.Fall through to the "incomplete byte" error only when every char in
incompleteCharsis a valid hex digit.Tests Added
Hex.test.tsDomainSeparator.test.tsSigningKey.test.tsNetworkId.test.tsTotal platform-js test count: 35 → 63, all passing.