Skip to content

Commit

Permalink
Ensure that UTF-8 is used to read and write snippets in operation macro
Browse files Browse the repository at this point in the history
Fixes gh-696
  • Loading branch information
wilkinsona committed Sep 14, 2020
1 parent 3161f10 commit ed5921f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def read_snippets(snippets_dir, snippet_names, parent, operation,

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,
Expand Down Expand Up @@ -93,7 +94,7 @@ def append_snippet_block(content, snippet, section_id,

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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -199,7 +200,7 @@ public void titleOfCustomSnippetCanBeCustomizedUsingDocumentAttribute() throws E

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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2 id="_custom_snippet">Custom snippet</h2>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h2 id="_custom_snippet">Customized title</h2>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h2 id="_custom_snippet">Custom snippet</h2>
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[source,http,options="nowrap"]
----
mycustomsnippet
mycustomsnippet-äöü
----

0 comments on commit ed5921f

Please sign in to comment.