From 343d181a4eee06d47b4cdd9bb04487a6b77e1abe Mon Sep 17 00:00:00 2001 From: Bastian Date: Thu, 25 Aug 2022 13:02:41 +0200 Subject: [PATCH] KEYCLOAK-18289: use utf-8 encoding for simplehttp (#8025) Co-authored-by: Stian Thorgersen --- .../org/keycloak/broker/provider/util/SimpleHttp.java | 2 +- .../org/keycloak/broker/provider/util/SimpleHttpTest.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java b/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java index 0a6addc3dd..5dcb0952d0 100755 --- a/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java +++ b/server-spi-private/src/main/java/org/keycloak/broker/provider/util/SimpleHttp.java @@ -314,7 +314,7 @@ public class SimpleHttp { } } - return new UrlEncodedFormEntity(urlParameters); + return new UrlEncodedFormEntity(urlParameters, StandardCharsets.UTF_8); } public static class Response { diff --git a/server-spi-private/src/test/java/org/keycloak/broker/provider/util/SimpleHttpTest.java b/server-spi-private/src/test/java/org/keycloak/broker/provider/util/SimpleHttpTest.java index a39443f59e..1058deb582 100644 --- a/server-spi-private/src/test/java/org/keycloak/broker/provider/util/SimpleHttpTest.java +++ b/server-spi-private/src/test/java/org/keycloak/broker/provider/util/SimpleHttpTest.java @@ -23,6 +23,7 @@ import org.junit.runners.Parameterized.Parameters; import org.keycloak.common.util.StreamUtil; import java.io.IOException; +import java.net.URLEncoder; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -99,6 +100,13 @@ public final class SimpleHttpTest { assertEquals("{\"value\":\"" + value + "\"}", client.data); } + @Test + public void requestWithEncodingParam() throws IOException { + HttpClientMock client = new HttpClientMock(); + SimpleHttp.doPost("", client).param("dummy", value).asResponse(); + assertEquals("dummy=" + URLEncoder.encode(value, "UTF-8"), client.data); + } + public static final class DummyEntity { public String value; public DummyEntity(String value) {