Parse host from authority in UriComponentsBuilder.uri when unsuccessful #33608
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.
According to rain.drop in kakaopay, it appears that
UriComponentsBuilder#fromUri
has a bug where it fails to recognize hostnames containing underscores (_) due to a limitation ofjava.net.URI
. In contrast,UriComponentsBuilder#fromUriString
successfully parses these hostnames usingURI_PATTERN
.For example,
UriComponentsBuilder.fromUri(URI("kakaopay://payweb_tab"))
results in a nullhost
butpayweb_tab
becomes itsauthority
, unlikeUriComponentsBuilder.fromUriString("kakaopay://payweb_tab")
says itshost
andauthority
are bothpayweb_tab
.This issue arises because java.net.URI adheres to RFC 2396 and RFC 2732 but does not conform to RFC 3986, which allows underscores in hostnames as per the
URI_PATTERN
. This inconsistency can lead to problems when parsing such URIs with the standard URI class, potentially resulting in thegetHost()
method returning null.https://github.com/openjdk/jdk/blob/ae4d2f15901bf02efceaac26ee4aa3ae666bf467/src/java.base/share/classes/java/net/URI.java#L3513-L3520