Skip to content

Parse host from authority in UriComponentsBuilder.uri when unsuccessful #33608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

yhkee0404
Copy link

@yhkee0404 yhkee0404 commented Sep 30, 2024

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 of java.net.URI. In contrast, UriComponentsBuilder#fromUriString successfully parses these hostnames using URI_PATTERN.

For example, UriComponentsBuilder.fromUri(URI("kakaopay://payweb_tab")) results in a null host but payweb_tab becomes its authority, unlike UriComponentsBuilder.fromUriString("kakaopay://payweb_tab") says its host and authority are both payweb_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 the getHost() method returning null.

https://github.com/openjdk/jdk/blob/ae4d2f15901bf02efceaac26ee4aa3ae666bf467/src/java.base/share/classes/java/net/URI.java#L3513-L3520

@pivotal-cla
Copy link

@yhkee0404 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 30, 2024
@pivotal-cla
Copy link

@yhkee0404 Thank you for signing the Contributor License Agreement!

@bclozel
Copy link
Member

bclozel commented Sep 30, 2024

Thanks for the proposal, but I don't think we should add a special case for this; java.net.URI has a specific behavior and we should not change it because it would create inconsistencies. fromUriString uses a different parsing algorithm. We will refine our documentation and stance on this matter in #33542

@bclozel bclozel closed this Sep 30, 2024
@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants