Skip to content

Do not write BOM to results#3071

Merged
timcassell merged 3 commits intodotnet:masterfrom
martincostello:gh-3070
Apr 1, 2026
Merged

Do not write BOM to results#3071
timcassell merged 3 commits intodotnet:masterfrom
martincostello:gh-3070

Conversation

@martincostello
Copy link
Copy Markdown
Member

Do not write UTF-8 BOM to results files.

Fixes #3070.

All the tests choose their own encoding, rather than using the default constructor the real exporters use, e.g.:

using var stream = new MemoryStream();
using (var writer = new CancelableStreamWriter(stream, Encoding.UTF8, 1024, leaveOpen: true))
{
await exporter.ExportAsync(summary, writer, cancellationToken).ConfigureAwait(false);
}
stream.Position = 0;
using var reader = new StreamReader(stream, Encoding.UTF8);
string? line;
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
{
logger.WriteLine(line);
}
}

vs:

using var writer = new CancelableStreamWriter(fileStream);

I'm happy to add/update some tests for this issue if you have opinions on how you'd like to verify this exactly.

Do not write UTF-8 BOM to results files.

Fixes dotnet#3070.
Copilot AI review requested due to automatic review settings April 1, 2026 17:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an unintended behavior change where result files (e.g., JSON exports) are written with a UTF-8 BOM, which breaks some downstream consumers (notably JavaScript JSON parsing in CI workflows).

Changes:

  • Change CancelableStreamWriter’s default encoding from Encoding.UTF8 (BOM-emitting) to a UTF-8 encoding configured to not emit a BOM.
  • Introduce a cached UTF8NoBOM encoding instance used by the default CancelableStreamWriter(Stream) constructor.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/BenchmarkDotNet/Helpers/CancelableStreamWriter.cs Outdated
Comment thread src/BenchmarkDotNet/Helpers/CancelableStreamWriter.cs Outdated
Use existing shared field.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment thread src/BenchmarkDotNet/Helpers/CancelableStreamWriter.cs Outdated
@timcassell timcassell merged commit 2fdddb7 into dotnet:master Apr 1, 2026
11 checks passed
@martincostello martincostello deleted the gh-3070 branch April 1, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.16] --json files are written with UTF-8 BOM

3 participants