6mmLIU opened a new pull request, #15657:
URL: https://github.com/apache/dubbo/pull/15657

   ## What is the purpose of the change?
   Introduce an overload `StringUtils.isNumeric(String str, boolean allowDot, 
boolean allowSign)` to optionally validate leading `+`/`-` signs while keeping 
the existing API and behavior unchanged. Callers that do not need sign support 
can continue using the original method without any behavior change.
   
   ## Background & motivation
   Several call sites need numeric validation for signed integers/decimals. 
Today they either re-implement ad-hoc checks or reject valid inputs with a 
leading sign. Centralizing the logic in `StringUtils` reduces duplication and 
subtle bugs, while remaining strictly backward compatible.
   
   ## Brief changelog
   - Add `isNumeric(String, boolean allowDot, boolean allowSign)` overload.
   - Keep the original signature and semantics intact.
   - Leading sign is accepted only at position 0 when `allowSign == true`; a 
lone sign (e.g. `"+"`, `"-"`) is still invalid.
   - Dot handling is identical to the current implementation: at most one dot 
if `allowDot == true`; otherwise any dot fails.
   - Only ASCII digits are considered numeric (no scientific notation like 
`1e3`).
   
   ## Verifying this change
   Unit tests cover positive and negative paths, including:
   - `"-1"` with `allowSign=true` passes; `"+"` / `"-"` alone fail.
   - `"+1.23"` passes when `allowDot=true && allowSign=true`.
   - Multiple dots, embedded non-digits, and null/empty strings fail.
   - Original method keeps returning `false` for signed inputs (backward 
compatibility check).
   
   ## Compatibility, risk and docs
   - **Backward compatible**: no changes to the existing method’s behavior.
   - JavaDoc added for the new overload; no external docs need updating.
   - Non-goals: scientific notation, locale digits, and whitespace trimming.
   
   ## Issue
   Fixes #<issue-id>
   
   ## Checklist
   - [x] A GitHub issue is linked (`Fixes #<issue-id>`).
   - [x] Clear description of motivation, design, and behavior boundaries.
   - [x] Unit tests added for signed/unsigned and edge cases.
   - [x] No breaking changes for existing callers.
   - [x] CI: run `mvn -q -pl dubbo-common -am test` (ensure a networked 
environment so parent POM and dependencies resolve).
   


-- 
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: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to