Skip to content

Commit 03ec060

Browse files
[automated] Merge branch 'vs17.12' => 'main' (#10747)
1 parent 4fdfc9b commit 03ec060

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/Build/BuildCheck/Infrastructure/EditorConfig/EditorConfigFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal static EditorConfigFile Parse(string text)
8181
// dictionary, but we also use a case-insensitive key comparer when doing lookups
8282
var activeSectionProperties = ImmutableDictionary.CreateBuilder<string, string>(StringComparer.OrdinalIgnoreCase);
8383
string activeSectionName = "";
84-
var lines = string.IsNullOrEmpty(text) ? Array.Empty<string>() : text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
84+
var lines = string.IsNullOrEmpty(text) ? Array.Empty<string>() : text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
8585

8686
foreach(var line in lines)
8787
{

src/BuildCheck.UnitTests/EditorConfigParser_Tests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void EditorconfigFileDiscovery_RootTrue()
8181
""");
8282

8383
var parser = new EditorConfigParser();
84-
var listOfEditorConfigFile = parser.DiscoverEditorConfigFiles(Path.Combine(workFolder1.Path, "subfolder", "projectfile.proj") ).ToList();
84+
var listOfEditorConfigFile = parser.DiscoverEditorConfigFiles(Path.Combine(workFolder1.Path, "subfolder", "projectfile.proj")).ToList();
8585
// should be one because root=true so we do not need to go further
8686
listOfEditorConfigFile.Count.ShouldBe(1);
8787
listOfEditorConfigFile[0].IsRoot.ShouldBeTrue();
@@ -116,4 +116,31 @@ public void EditorconfigFileDiscovery_RootFalse()
116116
listOfEditorConfigFile[0].IsRoot.ShouldBeFalse();
117117
listOfEditorConfigFile[0].NamedSections[0].Name.ShouldBe("*.csproj");
118118
}
119+
120+
[Fact]
121+
public void Parse_HandlesDifferentLineEndings()
122+
{
123+
var mixedEndingsText = "root = true\r\n" +
124+
"[*.cs]\n" +
125+
"indent_style = space\r\n" +
126+
"indent_size = 4\n" +
127+
"[*.md]\r\n" +
128+
"trim_trailing_whitespace = true";
129+
130+
var result = EditorConfigFile.Parse(mixedEndingsText);
131+
132+
result.IsRoot.ShouldBeTrue("Root property should be true");
133+
result.NamedSections.Length.ShouldBe(2);
134+
135+
var csSection = result.NamedSections.FirstOrDefault(s => s.Name == "*.cs");
136+
csSection.ShouldNotBeNull();
137+
csSection.Properties.Count.ShouldBe(2);
138+
csSection.Properties["indent_style"].ShouldBe("space");
139+
csSection.Properties["indent_size"].ShouldBe("4");
140+
141+
var mdSection = result.NamedSections.FirstOrDefault(s => s.Name == "*.md");
142+
mdSection.ShouldNotBeNull();
143+
mdSection.Properties.Count.ShouldBe(1);
144+
mdSection.Properties["trim_trailing_whitespace"].ShouldBe("true");
145+
}
119146
}

src/MSBuild/TerminalLogger/TerminalLogger.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ public ProjectContext(BuildEventContext context)
221221
/// </summary>
222222
private bool _showCommandLine = false;
223223

224+
private uint? _originalConsoleMode;
225+
224226
/// <summary>
225227
/// Default constructor, used by the MSBuild logger infra.
226228
/// </summary>
@@ -263,6 +265,8 @@ public void Initialize(IEventSource eventSource, int nodeCount)
263265
/// <inheritdoc/>
264266
public void Initialize(IEventSource eventSource)
265267
{
268+
(_, _, _originalConsoleMode) = NativeMethodsShared.QueryIsScreenAndTryEnableAnsiColorCodes();
269+
266270
ParseParameters();
267271

268272
eventSource.BuildStarted += BuildStarted;
@@ -358,6 +362,8 @@ private bool TryApplyShowCommandLineParameter(string? parameterValue)
358362
/// <inheritdoc/>
359363
public void Shutdown()
360364
{
365+
NativeMethodsShared.RestoreConsoleMode(_originalConsoleMode);
366+
361367
_cts.Cancel();
362368
_refresher?.Join();
363369
Terminal.Dispose();

0 commit comments

Comments
 (0)