sahvx655-wq opened a new pull request, #395:
URL: https://github.com/apache/commons-validator/pull/395
Thanks for your contribution to Apache Commons!
- [x] Read the contribution guidelines for this project.
- [ ] Read the ASF Generative Tooling Guidance if you use Artificial
Intelligence (AI).
- [ ] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute?
- [ ] Run a successful build using the default Maven goal with `mvn`; that's
`mvn` on the command line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body.
`RegexValidator.validate` has a single capturing group fast path that
returns `matcher.group(1)` directly. When the sole group is optional and does
not take part in the match, for example `new RegexValidator("^(abc)?def$")`
against `"def"`, that group is null and so `validate` hands back null. I came
across this while tracing why the three public methods disagreed on one input:
`isValid` returns true, `match` returns a one element array holding null, yet
`validate` returns null, which its own Javadoc reserves for an invalid value.
The multi group path already skips null groups and aggregates to an empty
string, so the defect is confined to the `count == 1` branch. I have made that
branch fall back to an empty string when the group is absent, which lines up
with the aggregation behaviour and the documented contract. Left alone, any
caller that reads a null from `validate` as a rejection silently drops valid
input, and because `isValid` still reports the value as good the mismatch is
easy to miss. The added test exercises the optional group case and fails on the
current code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]