Skip to content

Commit ed5921f

Browse files
committed
Ensure that UTF-8 is used to read and write snippets in operation macro
Fixes gh-696
1 parent 3161f10 commit ed5921f

File tree

6 files changed

+8
-6
lines changed

6 files changed

+8
-6
lines changed

spring-restdocs-asciidoctor-support/src/main/resources/extensions/operation_block_macro.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def read_snippets(snippets_dir, snippet_names, parent, operation,
3737

3838
def do_read_snippets(snippets, parent, operation, snippet_titles)
3939
content = StringIO.new
40+
content.set_encoding "UTF-8"
4041
section_id = parent.id
4142
snippets.each do |snippet|
4243
append_snippet_block(content, snippet, section_id,
@@ -93,7 +94,7 @@ def append_snippet_block(content, snippet, section_id,
9394

9495
def write_content(content, snippet, operation)
9596
if File.file? snippet.path
96-
content.puts File.readlines(snippet.path).join
97+
content.puts File.readlines(snippet.path, :encoding => 'UTF-8').join
9798
else
9899
warn "Snippet #{snippet.name} not found at #{snippet.path} for"\
99100
" operation #{operation}"

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.net.URISyntaxException;
22+
import java.nio.charset.StandardCharsets;
2223
import java.nio.file.Files;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
@@ -199,7 +200,7 @@ public void titleOfCustomSnippetCanBeCustomizedUsingDocumentAttribute() throws E
199200

200201
private String getExpectedContentFromFile(String fileName) throws URISyntaxException, IOException {
201202
Path filePath = Paths.get(this.getClass().getResource("/operations/" + fileName + ".html").toURI());
202-
String content = new String(Files.readAllBytes(filePath));
203+
String content = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
203204
if (isWindows()) {
204205
return content.replace("\r\n", "\n");
205206
}

spring-restdocs-asciidoctor/src/test/resources/operations/all-snippets.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h2 id="_custom_snippet">Custom snippet</h2>
1313
<div class="sectionbody">
1414
<div class="listingblock">
1515
<div class="content">
16-
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet</code></pre>
16+
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet-äöü</code></pre>
1717
</div>
1818
</div>
1919
</div>

spring-restdocs-asciidoctor/src/test/resources/operations/custom-snippet-custom-title.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ <h2 id="_custom_snippet">Customized title</h2>
33
<div class="sectionbody">
44
<div class="listingblock">
55
<div class="content">
6-
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet</code></pre>
6+
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet-äöü</code></pre>
77
</div>
88
</div>
99
</div>

spring-restdocs-asciidoctor/src/test/resources/operations/custom-snippet-default-title.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ <h2 id="_custom_snippet">Custom snippet</h2>
33
<div class="sectionbody">
44
<div class="listingblock">
55
<div class="content">
6-
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet</code></pre>
6+
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet-äöü</code></pre>
77
</div>
88
</div>
99
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[source,http,options="nowrap"]
22
----
3-
mycustomsnippet
3+
mycustomsnippet-äöü
44
----

0 commit comments

Comments
 (0)