Ensure that UTF-8 is used to read and write snippets in operation macro

Fixes gh-696
This commit is contained in:
Andy Wilkinson
2020-09-14 09:11:28 +01:00
parent 3161f10b51
commit ed5921fe83
6 changed files with 8 additions and 6 deletions

View File

@@ -37,6 +37,7 @@ class OperationBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
def do_read_snippets(snippets, parent, operation, snippet_titles)
content = StringIO.new
content.set_encoding "UTF-8"
section_id = parent.id
snippets.each do |snippet|
append_snippet_block(content, snippet, section_id,
@@ -93,7 +94,7 @@ class OperationBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor
def write_content(content, snippet, operation)
if File.file? snippet.path
content.puts File.readlines(snippet.path).join
content.puts File.readlines(snippet.path, :encoding => 'UTF-8').join
else
warn "Snippet #{snippet.name} not found at #{snippet.path} for"\
" operation #{operation}"

View File

@@ -19,6 +19,7 @@ package org.springframework.restdocs.asciidoctor;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -199,7 +200,7 @@ public abstract class AbstractOperationBlockMacroTests {
private String getExpectedContentFromFile(String fileName) throws URISyntaxException, IOException {
Path filePath = Paths.get(this.getClass().getResource("/operations/" + fileName + ".html").toURI());
String content = new String(Files.readAllBytes(filePath));
String content = new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8);
if (isWindows()) {
return content.replace("\r\n", "\n");
}

View File

@@ -13,7 +13,7 @@
<div class="sectionbody">
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet</code></pre>
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet-äöü</code></pre>
</div>
</div>
</div>

View File

@@ -3,7 +3,7 @@
<div class="sectionbody">
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet</code></pre>
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet-äöü</code></pre>
</div>
</div>
</div>

View File

@@ -3,7 +3,7 @@
<div class="sectionbody">
<div class="listingblock">
<div class="content">
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet</code></pre>
<pre class="highlight nowrap"><code class="language-http" data-lang="http">mycustomsnippet-äöü</code></pre>
</div>
</div>
</div>

View File

@@ -1,4 +1,4 @@
[source,http,options="nowrap"]
----
mycustomsnippet
mycustomsnippet-äöü
----