From c8a63709f290ef61b51fc48b7f0b2b4a1f067ae0 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Mon, 16 May 2022 09:48:54 +0200 Subject: [PATCH] =?UTF-8?q?#1792=20-=20Fix=20double=20encoding=20of=20requ?= =?UTF-8?q?est=20parameters=20in=20LinkBuilderSupport.toUri(=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../springframework/hateoas/server/core/LinkBuilderSupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/hateoas/server/core/LinkBuilderSupport.java b/src/main/java/org/springframework/hateoas/server/core/LinkBuilderSupport.java index 9d935673..adf22c26 100644 --- a/src/main/java/org/springframework/hateoas/server/core/LinkBuilderSupport.java +++ b/src/main/java/org/springframework/hateoas/server/core/LinkBuilderSupport.java @@ -119,7 +119,7 @@ public abstract class LinkBuilderSupport implements LinkB * @see org.springframework.hateoas.LinkBuilder#toUri() */ public URI toUri() { - return components.toUri().normalize(); + return URI.create(components.toUriString()); } public T addAffordances(Collection affordances) {