Validate hex input strictly - #33
Merged
Merged
Conversation
decode(), Str::encode(..., 'hex') and Str::decodeHex() only required
one hex digit somewhere in the input, removed every "0x" occurrence
rather than just the prefix, and let hexdec() silently drop invalid
characters (e.g. decode("0x8zz1") -> "8z", encode("0xzz") -> "zz").
decode() also padded odd-length input (0x8 -> 08).
Strip only a leading 0x, require the rest to be hex digits (anchored
with \A...\z so a trailing newline is rejected), and reject odd-length
input in decode(). Encoding still pads odd-length hex ("0x0" -> "00").
Add regression vectors for invalid and still-valid hex input.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #33 +/- ##
=============================================
+ Coverage 84.27% 94.44% +10.16%
- Complexity 59 61 +2
=============================================
Files 3 3
Lines 159 162 +3
=============================================
+ Hits 134 153 +19
+ Misses 25 9 -16 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
decode(), Str::encode(…, 'hex') and Str::decodeHex() accepted malformed hex:
Now only a leading 0x is stripped and the rest must be hex digits; a trailing newline is also rejected. decode() rejects odd-length input. Encoding still pads odd-length hex ("0x0" → "00"), and uppercase digits are still accepted.
Behavior change: these inputs now throw InvalidArgumentException. That includes encode("0xhello"), which used to produce invalid output (830hello).
Adds regression vectors for invalid and still-valid hex input.
🤖 Generated with Claude Code (https://claude.com/claude-code)