wy471x opened a new pull request, #6456:
URL: https://github.com/apache/shenyu/pull/6456
Replace raw split(":") with IPv6-aware host:port parsing using bracket
notation detection and java.net.URI to avoid breaking IPv6 addresses
like [2001:db8::1]:8080 in health checks, discovery, and API doc loading.
<!-- Describe your PR here; e.g. Fixes #issueNo -->
<!--
Thank you for proposing a pull request. This template will guide you through
the essential steps necessary for a pull request.
-->
Make sure that:
- [X] You have read the [contribution
guidelines](https://shenyu.apache.org/community/contributor-guide).
- [X] You submit test cases (unit or integration tests) that back your
changes.
- [X] Your local test passed `./mvnw clean install
-Dmaven.javadoc.skip=true`.
## Summary of All Changes
### Problem
Four files parsed upstream URLs/host:port strings by splitting on :. This
broke
IPv6 addresses like [2001:db8::1]:8080 — internal colons caused host
truncation,
wrong port parsing, or NumberFormatException.
### Files Changed (7)
shenyu-common/.../utils/IpUtils.java — Added parseHostPort(String
upstreamUrl), the
canonical implementation for parsing host:port or [ipv6]:port strings.
Returns
[host, port], defaulting port to "80".
shenyu-common/.../utils/UpstreamCheckUtils.java — Rewrote checkUrl: uses
java.net.URI for http:///https:// URLs (native IPv6 support), delegates
bare
host:port parsing to IpUtils.parseHostPort().
shenyu-admin/.../utils/CommonUpstreamUtils.java — parseHostPort()
delegates to
IpUtils.parseHostPort(). buildUrl() now wraps IPv6 hosts in brackets:
buildUrl("2001:db8::1", 8080) → "[2001:db8::1]:8080". Fixed dead
Optional.of(...).orElse(null).
shenyu-admin/.../impl/LoadServiceDocEntryImpl.java — Both getInstances2()
and
getInstances() replaced split(":") with
CommonUpstreamUtils.parseHostPort().
shenyu-admin/.../transfer/DiscoveryTransfer.java — mapToCommonUpstream()
and
mapToDiscoveryUpstreamData() replaced split(":") with parseHostPort().
Fixed
discarded Optional null-check.
shenyu-admin/.../CommonUpstreamUtilsTest.java — 8 new tests for
parseHostPort
(IPv4/IPv6/hostname) and buildUrl IPv6 bracketing.
shenyu-common/.../UpstreamCheckUtilsTest.java — 3 new tests verifying IPv6
URLs
parse without exceptions.
close [#6442](https://github.com/apache/shenyu/issues/6442)
--
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]