From f8cbb3b63c948df20064eec8dec7d9dcf5f58717 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 23 Sep 2015 20:51:44 +0100 Subject: [PATCH] Avoid using UTF-8 characters in source code Using UTF-8 in the source can be problematic on platforms that are not configured to use UTF-8 by default. This commit replaces a number of strings with UTF-8 characters in them with an equivalent ASCII string that uses unicode character escapes. --- .../restdocs/http/HttpRequestSnippetTests.java | 7 ++++--- .../restdocs/http/HttpResponseSnippetTests.java | 7 ++++--- .../preprocess/PatternReplacingContentModifierTests.java | 5 +++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java index 55cc9a07..bd93a77c 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java @@ -87,17 +87,18 @@ public class HttpRequestSnippetTests { @Test public void postRequestWithCharset() throws IOException { + String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4"; this.snippet.expectHttpRequest("post-request-with-charset").withContents( httpRequest(RequestMethod.POST, "/foo") .header(HttpHeaders.HOST, "localhost") .header("Content-Type", "text/plain;charset=UTF-8") - .content("こんにちわ, 世界")); // Hello, World in Japanese + .content(japaneseContent)); new HttpRequestSnippet().document(new OperationBuilder( "post-request-with-charset", this.snippet.getOutputDirectory()) .request("http://localhost/foo").method("POST") - .header("Content-Type", "text/plain;charset=UTF-8").content("こんにちわ, 世界") - .build()); + .header("Content-Type", "text/plain;charset=UTF-8") + .content(japaneseContent).build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java index cd6650f0..c40dff68 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java @@ -86,13 +86,14 @@ public class HttpResponseSnippetTests { @Test public void responseWithCharset() throws IOException { + String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4"; this.snippet.expectHttpResponse("response-with-charset").withContents( httpResponse(HttpStatus.OK).header("Content-Type", - "text/plain;charset=UTF-8").content("コンテンツ")); + "text/plain;charset=UTF-8").content(japaneseContent)); new HttpResponseSnippet().document(new OperationBuilder("response-with-charset", this.snippet.getOutputDirectory()).response() - .header("Content-Type", "text/plain;charset=UTF-8").content("コンテンツ") - .build()); + .header("Content-Type", "text/plain;charset=UTF-8") + .content(japaneseContent).build()); } @Test diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java index 8fedbc3d..1046cad9 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java @@ -48,12 +48,13 @@ public class PatternReplacingContentModifierTests { @Test public void encodingIsPreserved() { + String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4"; Pattern pattern = Pattern.compile("[0-9]+"); PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier( pattern, "<>"); - assertThat(contentModifier.modifyContent("こんにちわ, 世界 123".getBytes(), + assertThat(contentModifier.modifyContent((japaneseContent + " 123").getBytes(), new MediaType("text", "plain", Charset.forName("UTF-8"))), - is(equalTo("こんにちわ, 世界 <>".getBytes()))); + is(equalTo((japaneseContent + " <>").getBytes()))); } }