Skip to content

Commit

Permalink
[automated] Merge branch 'vs17.12' => 'main' (dotnet#10747)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 3, 2024
1 parent 4fdfc9b commit 03ec060
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal static EditorConfigFile Parse(string text)
// dictionary, but we also use a case-insensitive key comparer when doing lookups
var activeSectionProperties = ImmutableDictionary.CreateBuilder<string, string>(StringComparer.OrdinalIgnoreCase);
string activeSectionName = "";
var lines = string.IsNullOrEmpty(text) ? Array.Empty<string>() : text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
var lines = string.IsNullOrEmpty(text) ? Array.Empty<string>() : text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);

foreach(var line in lines)
{
Expand Down
29 changes: 28 additions & 1 deletion src/BuildCheck.UnitTests/EditorConfigParser_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void EditorconfigFileDiscovery_RootTrue()
""");

var parser = new EditorConfigParser();
var listOfEditorConfigFile = parser.DiscoverEditorConfigFiles(Path.Combine(workFolder1.Path, "subfolder", "projectfile.proj") ).ToList();
var listOfEditorConfigFile = parser.DiscoverEditorConfigFiles(Path.Combine(workFolder1.Path, "subfolder", "projectfile.proj")).ToList();
// should be one because root=true so we do not need to go further
listOfEditorConfigFile.Count.ShouldBe(1);
listOfEditorConfigFile[0].IsRoot.ShouldBeTrue();
Expand Down Expand Up @@ -116,4 +116,31 @@ public void EditorconfigFileDiscovery_RootFalse()
listOfEditorConfigFile[0].IsRoot.ShouldBeFalse();
listOfEditorConfigFile[0].NamedSections[0].Name.ShouldBe("*.csproj");
}

[Fact]
public void Parse_HandlesDifferentLineEndings()
{
var mixedEndingsText = "root = true\r\n" +
"[*.cs]\n" +
"indent_style = space\r\n" +
"indent_size = 4\n" +
"[*.md]\r\n" +
"trim_trailing_whitespace = true";

var result = EditorConfigFile.Parse(mixedEndingsText);

result.IsRoot.ShouldBeTrue("Root property should be true");
result.NamedSections.Length.ShouldBe(2);

var csSection = result.NamedSections.FirstOrDefault(s => s.Name == "*.cs");
csSection.ShouldNotBeNull();
csSection.Properties.Count.ShouldBe(2);
csSection.Properties["indent_style"].ShouldBe("space");
csSection.Properties["indent_size"].ShouldBe("4");

var mdSection = result.NamedSections.FirstOrDefault(s => s.Name == "*.md");
mdSection.ShouldNotBeNull();
mdSection.Properties.Count.ShouldBe(1);
mdSection.Properties["trim_trailing_whitespace"].ShouldBe("true");
}
}
6 changes: 6 additions & 0 deletions src/MSBuild/TerminalLogger/TerminalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public ProjectContext(BuildEventContext context)
/// </summary>
private bool _showCommandLine = false;

private uint? _originalConsoleMode;

/// <summary>
/// Default constructor, used by the MSBuild logger infra.
/// </summary>
Expand Down Expand Up @@ -263,6 +265,8 @@ public void Initialize(IEventSource eventSource, int nodeCount)
/// <inheritdoc/>
public void Initialize(IEventSource eventSource)
{
(_, _, _originalConsoleMode) = NativeMethodsShared.QueryIsScreenAndTryEnableAnsiColorCodes();

ParseParameters();

eventSource.BuildStarted += BuildStarted;
Expand Down Expand Up @@ -358,6 +362,8 @@ private bool TryApplyShowCommandLineParameter(string? parameterValue)
/// <inheritdoc/>
public void Shutdown()
{
NativeMethodsShared.RestoreConsoleMode(_originalConsoleMode);

_cts.Cancel();
_refresher?.Join();
Terminal.Dispose();
Expand Down

0 comments on commit 03ec060

Please sign in to comment.