Affects: \


Hi there,

I have a small enhancement to propose - how about exposing verify() method in the interface?

Use case: say, there is a webhooks service that exposes API to create webhoook subscriptions providing URLs; working with different systems some do provide already encoded URL and others expect URL yet to be encoded. Having the kind of method in interface would allow validating provided URL string before building UriComponent.

Workaround: try to build UriComponent w/o encoding and catch IAE and build with encoding along the way. Not perfect.

private UriComponents buildAndValidateUriComponents(String url, String sig) {
        var builder = UriComponentsBuilder.fromHttpUrl(url); // https://example.com/?code=56fJrWyfsNa5alHt95mc5S6ViiUUKYuTQUmGImaoWl8eTartOitEMQ==
        try {
            return builder.build(true);
        } catch (IllegalArgumentException ex) {
            return builder.build().encode();
        }
 }

Wdyt?

Comment From: bclozel

Sorry for the delayed feedback.

As outlined on the Javadoc of UriComponent#fromHttpUrl and by our own documentation on building links, this is not so clear cut. If the method doesn't throw an IllegalArgumentException, this doesn't mean that your URI has been properly parsed and that not issue will arise. There are still possible cases of double encoding or misinterpretation by the parser.

With that in mind, I don't think we can really implement such a verify contract here as we can't really guarantee the behavior (besides not throwing an exception). I'm declining this enhancement request as a result.

Thanks for reaching out with enhancement ideas!