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.
This commit is contained in:
@@ -87,17 +87,18 @@ public class HttpRequestSnippetTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void postRequestWithCharset() throws IOException {
|
public void postRequestWithCharset() throws IOException {
|
||||||
|
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
|
||||||
this.snippet.expectHttpRequest("post-request-with-charset").withContents(
|
this.snippet.expectHttpRequest("post-request-with-charset").withContents(
|
||||||
httpRequest(RequestMethod.POST, "/foo")
|
httpRequest(RequestMethod.POST, "/foo")
|
||||||
.header(HttpHeaders.HOST, "localhost")
|
.header(HttpHeaders.HOST, "localhost")
|
||||||
.header("Content-Type", "text/plain;charset=UTF-8")
|
.header("Content-Type", "text/plain;charset=UTF-8")
|
||||||
.content("こんにちわ, 世界")); // Hello, World in Japanese
|
.content(japaneseContent));
|
||||||
|
|
||||||
new HttpRequestSnippet().document(new OperationBuilder(
|
new HttpRequestSnippet().document(new OperationBuilder(
|
||||||
"post-request-with-charset", this.snippet.getOutputDirectory())
|
"post-request-with-charset", this.snippet.getOutputDirectory())
|
||||||
.request("http://localhost/foo").method("POST")
|
.request("http://localhost/foo").method("POST")
|
||||||
.header("Content-Type", "text/plain;charset=UTF-8").content("こんにちわ, 世界")
|
.header("Content-Type", "text/plain;charset=UTF-8")
|
||||||
.build());
|
.content(japaneseContent).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -86,13 +86,14 @@ public class HttpResponseSnippetTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void responseWithCharset() throws IOException {
|
public void responseWithCharset() throws IOException {
|
||||||
|
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
|
||||||
this.snippet.expectHttpResponse("response-with-charset").withContents(
|
this.snippet.expectHttpResponse("response-with-charset").withContents(
|
||||||
httpResponse(HttpStatus.OK).header("Content-Type",
|
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",
|
new HttpResponseSnippet().document(new OperationBuilder("response-with-charset",
|
||||||
this.snippet.getOutputDirectory()).response()
|
this.snippet.getOutputDirectory()).response()
|
||||||
.header("Content-Type", "text/plain;charset=UTF-8").content("コンテンツ")
|
.header("Content-Type", "text/plain;charset=UTF-8")
|
||||||
.build());
|
.content(japaneseContent).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -48,12 +48,13 @@ public class PatternReplacingContentModifierTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void encodingIsPreserved() {
|
public void encodingIsPreserved() {
|
||||||
|
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
|
||||||
Pattern pattern = Pattern.compile("[0-9]+");
|
Pattern pattern = Pattern.compile("[0-9]+");
|
||||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(
|
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(
|
||||||
pattern, "<<number>>");
|
pattern, "<<number>>");
|
||||||
assertThat(contentModifier.modifyContent("こんにちわ, 世界 123".getBytes(),
|
assertThat(contentModifier.modifyContent((japaneseContent + " 123").getBytes(),
|
||||||
new MediaType("text", "plain", Charset.forName("UTF-8"))),
|
new MediaType("text", "plain", Charset.forName("UTF-8"))),
|
||||||
is(equalTo("こんにちわ, 世界 <<number>>".getBytes())));
|
is(equalTo((japaneseContent + " <<number>>").getBytes())));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user