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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trim_trailing_whitespace = true
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
encoding = utf-8-bom
Copy link
Member

Choose a reason for hiding this comment

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

I copied this from roslyn, so it's likely busted over there too: https://github.com/dotnet/roslyn/blob/main/.editorconfig#L15

Copy link
Member Author

@jjonescz jjonescz Feb 9, 2023

Choose a reason for hiding this comment

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

No, I checked, Roslyn has charset correctly. encoding was wrong in Razor.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like the link you provided to Roslyn is already correct in main.

image

Copy link
Member

Choose a reason for hiding this comment

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

I swear to god it showed encoding on my screen 5 seconds ago...

charset = utf-8-bom

file_header_template = Copyright (c) .NET Foundation. All rights reserved.\nLicensed under the MIT license. See License.txt in the project root for license information.

Expand Down
1 change: 1 addition & 0 deletions src/Compiler/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ insert_final_newline = true

[*.cs]
indent_size = 4
charset = utf-8-bom
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.AspNetCore.Razor.Language.Legacy;
using Xunit;
Expand All @@ -18,6 +19,9 @@ public abstract class RazorBaselineIntegrationTestBase : RazorIntegrationTestBas
{
private static readonly AsyncLocal<string> _directoryPath = new AsyncLocal<string>();

// UTF-8 with BOM
private static readonly Encoding _baselineEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true);

protected RazorBaselineIntegrationTestBase(bool? generateBaselines = null)
{
TestProjectRoot = TestProject.GetProjectDirectory(GetType());
Expand All @@ -36,7 +40,7 @@ public static string DirectoryPath
}

#if GENERATE_BASELINES
protected bool GenerateBaselines { get; } = true;
protected bool GenerateBaselines { get; } = true;
#else
protected bool GenerateBaselines { get; } = false;
#endif
Expand Down Expand Up @@ -250,12 +254,12 @@ private string GetBaselineFilePath(RazorCodeDocument codeDocument, string extens
private static void WriteBaseline(string text, string filePath)
{
var lines = text.Replace("\r", "").Replace("\n", "\r\n");
File.WriteAllText(filePath, text);
File.WriteAllText(filePath, text, _baselineEncoding);
}

private static void WriteBaseline(string[] lines, string filePath)
{
using (var writer = new StreamWriter(File.Open(filePath, FileMode.Create)))
using (var writer = new StreamWriter(File.Open(filePath, FileMode.Create), _baselineEncoding))
{
// Force windows-style line endings so that we're consistent. This isn't
// required for correctness, but will prevent churn when developing on OSX.
Expand Down