reject non-hex characters in decodeHex#2627
Closed
netliomax25-code wants to merge 1 commit into
Closed
Conversation
✅ All tests passed ✅🏷️ Commit: 5136de2 Learn more about TestLens at testlens.app. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens EncodingGroovyMethods.decodeHex(String) so it rejects non-hex characters that Integer.parseInt(..., 16) would otherwise accept (e.g., leading +/- signs and non-ASCII digit characters), aligning behavior with the method’s documented NumberFormatException contract.
Changes:
- Replaced per-byte
Integer.parseInt(substring, 16)decoding with strict per-nibble ASCII-range decoding (0-9,a-f,A-F). - Added regression tests ensuring signed prefixes and non-ASCII digit characters are rejected.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java | Implements strict ASCII hex decoding via a new hexToNibble helper to reject +/- and non-ASCII digits. |
| src/test/groovy/groovy/HexTest.groovy | Adds new negative test cases for sign-prefixed and non-ASCII-digit hex strings. |
Contributor
|
Merged. Thanks! |
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.
Replaced the per-group parseInt with a strict per-nibble decode over the ASCII ranges 0-9/a-f/A-F. Valid hex decodes to the same bytes (checked against the old path for every byte value in both letter cases); the rejected inputs are covered by new cases in HexTest. Happy to file a Jira and link it.