Skip to content

Commit e5ba64d

Browse files
authored
Fix UTF-8 BOM settings (#8248)
* Consolidate EditorConfig charset * Emit baselines in UTF-8 BOM
1 parent 13534f7 commit e5ba64d

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trim_trailing_whitespace = true
1313
[*.{cs,csx,vb,vbx}]
1414
indent_size = 4
1515
insert_final_newline = true
16-
encoding = utf-8-bom
16+
charset = utf-8-bom
1717

1818
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.
1919

src/Compiler/.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ insert_final_newline = true
2121

2222
[*.cs]
2323
indent_size = 4
24+
charset = utf-8-bom
2425
dotnet_sort_system_directives_first = true
2526
dotnet_separate_import_directive_groups = false
2627

src/Compiler/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorBaselineIntegrationTestBase.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System;
77
using System.IO;
88
using System.Linq;
9+
using System.Text;
910
using System.Threading;
1011
using Microsoft.AspNetCore.Razor.Language.Legacy;
1112
using Xunit;
@@ -18,6 +19,9 @@ public abstract class RazorBaselineIntegrationTestBase : RazorIntegrationTestBas
1819
{
1920
private static readonly AsyncLocal<string> _directoryPath = new AsyncLocal<string>();
2021

22+
// UTF-8 with BOM
23+
private static readonly Encoding _baselineEncoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true);
24+
2125
protected RazorBaselineIntegrationTestBase(bool? generateBaselines = null)
2226
{
2327
TestProjectRoot = TestProject.GetProjectDirectory(GetType());
@@ -36,7 +40,7 @@ public static string DirectoryPath
3640
}
3741

3842
#if GENERATE_BASELINES
39-
protected bool GenerateBaselines { get; } = true;
43+
protected bool GenerateBaselines { get; } = true;
4044
#else
4145
protected bool GenerateBaselines { get; } = false;
4246
#endif
@@ -250,12 +254,12 @@ private string GetBaselineFilePath(RazorCodeDocument codeDocument, string extens
250254
private static void WriteBaseline(string text, string filePath)
251255
{
252256
var lines = text.Replace("\r", "").Replace("\n", "\r\n");
253-
File.WriteAllText(filePath, text);
257+
File.WriteAllText(filePath, text, _baselineEncoding);
254258
}
255259

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

0 commit comments

Comments
 (0)