Skip to content

Commit b02fcbe

Browse files
committed
Default to UTF-8 when reading operation content as a string
Fixes gh-689
1 parent 9162888 commit b02fcbe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-restdocs-core/src/main/java/org/springframework/restdocs/operation/AbstractOperationMessage.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.restdocs.operation;
1818

1919
import java.nio.charset.Charset;
20+
import java.nio.charset.StandardCharsets;
2021
import java.util.Arrays;
2122

2223
import org.springframework.http.HttpHeaders;
@@ -52,7 +53,10 @@ public HttpHeaders getHeaders() {
5253
public String getContentAsString() {
5354
if (this.content.length > 0) {
5455
Charset charset = extractCharsetFromContentTypeHeader();
55-
return (charset != null) ? new String(this.content, charset) : new String(this.content);
56+
if (charset == null) {
57+
charset = StandardCharsets.UTF_8;
58+
}
59+
return new String(this.content, charset);
5660
}
5761
return "";
5862
}

0 commit comments

Comments
 (0)