Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.io.OutputStreamWriter;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
Expand Down Expand Up @@ -162,7 +162,7 @@ private void writeAtomicallySecure(SecureDirectoryStream<Path> directory, Path r
try {
try (SeekableByteChannel channel = directory.newByteChannel(temporaryName, options);
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(Channels.newOutputStream(channel), Charset.defaultCharset()))) {
new OutputStreamWriter(Channels.newOutputStream(channel), StandardCharsets.UTF_8))) {
writer.write(content);
}
directory.move(temporaryName, directory, reportName);
Expand Down Expand Up @@ -218,7 +218,7 @@ public void writeAtomically(Path reportName, String content) throws IOException
try {
try (SeekableByteChannel channel = Files.newByteChannel(temporaryName, options);
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(Channels.newOutputStream(channel), Charset.defaultCharset()))) {
new OutputStreamWriter(Channels.newOutputStream(channel), StandardCharsets.UTF_8))) {
writer.write(content);
}
// Verify temp file is not a symlink before move
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardWatchEventKinds;
Expand Down Expand Up @@ -279,4 +280,20 @@ void containReportDirectory_rejectsSymlinkedAncestor(@TempDir Path tempDir) thro
IllegalArgumentException.class,
() -> ReportWriter.containReportDirectory(tempDir.toFile(), "linked/site"));
}

@Test
void writeReportToDisk_emitsUtf8ForNonAsciiContent(@TempDir Path tempDir) throws IOException {
String nonAsciiContent = "café 漢字 😀";
Path outputDir = tempDir.resolve("output");
Files.createDirectories(outputDir);

ReportWriter.writeReportToDisk(outputDir.toString(), "test.html", nonAsciiContent);

Path outputFile = outputDir.resolve("test.html");
assertTrue(Files.exists(outputFile));

byte[] writtenBytes = Files.readAllBytes(outputFile);
byte[] expectedBytes = nonAsciiContent.getBytes(StandardCharsets.UTF_8);
assertArrayEquals(expectedBytes, writtenBytes, "ReportWriter must emit UTF-8 bytes");
}
}
Loading