#1792 - Fix double encoding of request parameters in LinkBuilderSupport.toUri(…).

We unfortunately cannot use UriComponentsBuilder in a way that we can populate it with encoded parameters *and* expand encoded path variable values. We currently use ….buildAndExpand(…) which considers the values provided unencoded but we never actually call ….toUri() on the resulting UriComponents instance.

We unfortunately cannot fix the problem at its root, as the only alternative would be to call ….build(true) indicating values already encoded but that stumbles above the template variables still present in the original template.

The only workaround right now is never calling UriComponents.toUri() but ….toUriString() as that doesn't apply the pending encoding that's not actually needed as we start with fully encoded values in the first place.
This commit is contained in:
Oliver Drotbohm
2022-05-16 09:48:54 +02:00
parent d8579f5509
commit c8a63709f2

View File

@@ -119,7 +119,7 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
* @see org.springframework.hateoas.LinkBuilder#toUri()
*/
public URI toUri() {
return components.toUri().normalize();
return URI.create(components.toUriString());
}
public T addAffordances(Collection<Affordance> affordances) {