ns3154 opened a new pull request, #16350:
URL: https://github.com/apache/dubbo/pull/16350
## What is the purpose of the change?
`StringUtils.substringAfter(String, int)` is documented to return the empty
string when the
separator is not found ("If nothing is found, the empty string is
returned."), but it currently
returns the **original string** instead:
```
substringAfter("a:b", ':') -> "b" // ok
substringAfter("abc", ':') -> "abc" // expected "", actually returns "abc"
```
The not-found branch was copy-pasted from the neighbouring `substringBefore`
(whose contract *is*
to return the original string), which left `substringAfter` inconsistent
with both its own Javadoc
and its sibling `substringAfterLast` (which correctly returns the empty
string). It also diverges
from commons-lang3's `substringAfter`.
This PR makes `substringAfter` return `EMPTY_STRING` when the separator is
absent, and adds a unit
test (`testSubstringAfter`) covering the documented behaviour. The new test
fails before the fix
(`expected: <> but was: <abc>`) and passes after it; the full
`StringUtilsTest` suite stays green.
Fixes #16349
## Checklist
- [x] Make sure there is a
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Write necessary unit-test to verify your logic correction. If the new
feature or significant change is committed, please remember to add sample in
[dubbo samples](https://github.com/apache/dubbo-samples) project.
- [x] Make sure gitHub actions can pass. [Why the workflow is failing and
how to fix it?](../CONTRIBUTING.md)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]