Reject out-of-range color components in ColorConverter#420
Merged
garydgregory merged 1 commit intoJul 17, 2026
Merged
Conversation
the `JAVA_COLOR_PATTERN` label prefix included `\d`, so a bare triple like `1234,5,6` had its leading digit absorbed by the label and parsed as `4,5,6`, silently bypassing the `> 255` range check. bind the optional class-name label to its `[` so it can no longer eat digits from the numeric groups.
There was a problem hiding this comment.
Pull request overview
This pull request tightens ColorConverter’s parsing of Java Color#toString()-style strings to ensure malformed out-of-range numeric components can’t be accidentally accepted due to regex prefix greediness.
Changes:
- Updates
JAVA_COLOR_PATTERNto bind the optional class-name label to the opening[so digits can’t be consumed from the first numeric component. - Adds unit tests asserting that out-of-range component inputs like
1234,5,6are rejected with aConversionException.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/java/org/apache/commons/beanutils2/converters/ColorConverter.java | Adjusts the JAVA_COLOR_PATTERN so malformed numeric triples can’t be mis-parsed into in-range colors. |
| src/test/java/org/apache/commons/beanutils2/converters/ColorConverterTest.java | Adds regression tests covering previously-accepted out-of-range inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
garydgregory
added a commit
that referenced
this pull request
Jul 17, 2026
Member
|
TY @rootvector2 , merged 🚀 Please port to 1.X with the additional assertions in the new test. |
Contributor
Author
|
checked the 1.X branch and it has no |
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.
ColorConverter.parseToStringColoralready rejects color components above 255, but theJAVA_COLOR_PATTERNlabel prefix[A-Za-z\d._]+includes\d, so for a bare triple whose first component has four or more digits the greedy label swallows the leading digit and the first capture group only sees the trailing one to three digits.1234,5,6is parsed asColor(4,5,6), and1000,0,0/2550,0,0as black, so a malformed out-of-range value is accepted as a different in-range color instead of ever reaching the> 255check. Binding the optional class-name label to its opening[((?:[A-Za-z\d._]*\[)?) stops it absorbing digits from the numeric groups; every stringColor#toString()emits still parses the same, including class names that contain digits. Found while auditing the converters that parse untrusted strings.mvn; that'smvnon the command line by itself.