Skip to content
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

URIEditor prevents configuring URIs with encoded # sign #34262

Open
AdrianDiemerDev opened this issue Jan 15, 2025 · 2 comments
Open

URIEditor prevents configuring URIs with encoded # sign #34262

AdrianDiemerDev opened this issue Jan 15, 2025 · 2 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@AdrianDiemerDev
Copy link

I have a ConfigurationProperties class containing a property of type java.net.URI.

If I configure a value of file:///C:/some/path/with/#/in/it it (correctly) gets converted to a URI with a fragment component (which is not what I need in this case).
However, if I configure the value as a correctly encoded URI like this file:///C:/some/path/with/%23/in/it, It (incorrectly) gets converted to this URI: file:///C:/some/path/with/%2523/in/it.

I don't see a way to configure this URI so it gets bound corrrectly.

The reason for this is that the org.springframework.beans.propertyeditors.URIEditor tries to guess which part of the URI is correctly encoded and which isn't which is a task that's impossible to do correctly for all cases.

This has been improved upon several times #10673, #21123, #11743 but I think the approach is fundamentally flawed and the URIEditor should just not try to fix incorrectly encoded URIs by default.

The best workaround I could find was to use URLs instead of URIs.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 15, 2025
@rstoyanchev
Copy link
Contributor

To handle an encoded URI, the encode property should be off. This works:

String s = "file:///C:/some/path/with/%23/in/it";
URI uri = new URIEditor(true).createURI(s);
assertThat(uri.toString()).isEqualTo(s);

@rstoyanchev rstoyanchev added status: waiting-for-feedback We need additional information before we can continue in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 17, 2025
@AdrianDiemerDev
Copy link
Author

Yes, I know about the constructor but that doesn't help with the ConfigurationProperties binding because the binding uses a hard coded instance of URIEditor with encode = false. I couldn't find any way to replace that instance.

But even if it is somehow possible to replace it there, I don't think interpreting RFC3986 compliant URIs erroneously should be the default. I get that the idea is to make it more tolerant to wrongly encoded URIs but I don't think that should go at the expense of supporting correct URIs.

Though, I have no idea how to change this without introducing a breaking change...

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

3 participants