|
17 | 17 | package org.springframework.restdocs.operation.preprocess; |
18 | 18 |
|
19 | 19 | import java.net.URI; |
| 20 | +import java.nio.charset.StandardCharsets; |
20 | 21 | import java.util.Arrays; |
21 | 22 | import java.util.Collections; |
22 | 23 | import java.util.List; |
|
26 | 27 | import org.springframework.http.HttpHeaders; |
27 | 28 | import org.springframework.http.HttpMethod; |
28 | 29 | import org.springframework.http.HttpStatus; |
| 30 | +import org.springframework.http.MediaType; |
29 | 31 | import org.springframework.restdocs.operation.OperationRequest; |
30 | 32 | import org.springframework.restdocs.operation.OperationRequestFactory; |
31 | 33 | import org.springframework.restdocs.operation.OperationRequestPart; |
@@ -299,6 +301,32 @@ public void modifiedUriDoesNotGetDoubleEncoded() { |
299 | 301 |
|
300 | 302 | } |
301 | 303 |
|
| 304 | + @Test |
| 305 | + public void requestContentWithNonAsciiCharactersIsPreservedWhenCharsetIsIso88591() { |
| 306 | + this.preprocessor.scheme("https"); |
| 307 | + String original = "café http://localhost:12345 done"; |
| 308 | + HttpHeaders headers = new HttpHeaders(); |
| 309 | + headers.setContentType(MediaType.parseMediaType("text/plain;charset=ISO-8859-1")); |
| 310 | + OperationRequest request = this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET, |
| 311 | + original.getBytes(StandardCharsets.ISO_8859_1), headers, Collections.<OperationRequestPart>emptyList()); |
| 312 | + OperationRequest processed = this.preprocessor.preprocess(request); |
| 313 | + String result = new String(processed.getContent(), StandardCharsets.ISO_8859_1); |
| 314 | + assertThat(result).isEqualTo("café https://localhost:12345 done"); |
| 315 | + } |
| 316 | + |
| 317 | + @Test |
| 318 | + public void responseContentWithNonAsciiCharactersIsPreservedWhenCharsetIsIso88591() { |
| 319 | + this.preprocessor.scheme("https"); |
| 320 | + String original = "café http://localhost:12345 done"; |
| 321 | + HttpHeaders headers = new HttpHeaders(); |
| 322 | + headers.setContentType(MediaType.parseMediaType("text/plain;charset=ISO-8859-1")); |
| 323 | + OperationResponse response = this.responseFactory.create(HttpStatus.OK, headers, |
| 324 | + original.getBytes(StandardCharsets.ISO_8859_1)); |
| 325 | + OperationResponse processed = this.preprocessor.preprocess(response); |
| 326 | + String result = new String(processed.getContent(), StandardCharsets.ISO_8859_1); |
| 327 | + assertThat(result).isEqualTo("café https://localhost:12345 done"); |
| 328 | + } |
| 329 | + |
302 | 330 | @Test |
303 | 331 | public void resultingRequestHasCookiesFromOriginalRequst() { |
304 | 332 | List<RequestCookie> cookies = Arrays.asList(new RequestCookie("a", "alpha")); |
|
0 commit comments