From df60639d2e85d5e1fef011de40f6db587e2726d5 Mon Sep 17 00:00:00 2001 From: Alhuda Khan Date: Tue, 23 Jun 2026 23:20:15 +0530 Subject: [PATCH] encode string request body with utf-8 not the platform default Signed-off-by: Alhuda Khan --- core/src/main/java/feign/Request.java | 2 +- core/src/test/java/feign/RequestTest.java | 37 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 core/src/test/java/feign/RequestTest.java diff --git a/core/src/main/java/feign/Request.java b/core/src/main/java/feign/Request.java index a3627a164d..df3456d47e 100644 --- a/core/src/main/java/feign/Request.java +++ b/core/src/main/java/feign/Request.java @@ -554,7 +554,7 @@ public boolean isBinary() { } public static Body create(String data) { - return new Body(data.getBytes()); + return create(data, Util.UTF_8); } public static Body create(String data, Charset charset) { diff --git a/core/src/test/java/feign/RequestTest.java b/core/src/test/java/feign/RequestTest.java new file mode 100644 index 0000000000..9a40c1f521 --- /dev/null +++ b/core/src/test/java/feign/RequestTest.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2012 The Feign Authors (feign@commonhaus.dev) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package feign; + +import static feign.Util.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +import feign.Request.Body; +import org.junit.jupiter.api.Test; + +public class RequestTest { + + @Test + void stringBodyIsEncodedWithUtf8NotThePlatformDefault() { + String content = "spécial-çhars-€"; + + Body body = Body.create(content); + + assertThat(body.asBytes()).isEqualTo(content.getBytes(UTF_8)); + assertThat(body.getEncoding()).hasValue(UTF_8); + assertThat(body.isBinary()).isFalse(); + assertThat(body.asString()).isEqualTo(content); + } +}