Use form charset in ServletServerHttpRequest
Closes gh-34675
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user