Use form charset in ServletServerHttpRequest

Closes gh-34675
This commit is contained in:
rstoyanchev
2025-04-02 09:05:40 +01:00
parent e01ad5a08d
commit 290c9c4a19
2 changed files with 28 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.http.server;
import java.io.IOException;
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
@@ -217,6 +218,16 @@ class ServletServerHttpRequestTests {
assertThat(request.getHeaders().getContentLength()).isEqualTo(contentLength);
}
@Test // gh-34675
void getFormBodyWithNotUtf8Charset() throws IOException {
String charset = "windows-1251";
mockRequest.setContentType("application/x-www-form-urlencoded; charset=" + charset);
mockRequest.setMethod("POST");
mockRequest.addParameter("x", URLDecoder.decode("%e0%e0%e0", charset));
assertFormContent("x=%E0%E0%E0");
}
private int assertFormContent(String expected) throws IOException {
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
byte[] content = expected.getBytes(StandardCharsets.UTF_8);