From 2ff7f21a880e868f6d5ca57b2c594f80f61a32a2 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 1 Oct 2024 15:43:25 +0200 Subject: [PATCH 1/2] fix parsing .editorconfig line endings, add a unit test --- .../EditorConfig/EditorConfigFile.cs | 2 +- .../EditorConfigParser_Tests.cs | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Build/BuildCheck/Infrastructure/EditorConfig/EditorConfigFile.cs b/src/Build/BuildCheck/Infrastructure/EditorConfig/EditorConfigFile.cs index d2f93664369..e0417966263 100644 --- a/src/Build/BuildCheck/Infrastructure/EditorConfig/EditorConfigFile.cs +++ b/src/Build/BuildCheck/Infrastructure/EditorConfig/EditorConfigFile.cs @@ -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(StringComparer.OrdinalIgnoreCase); string activeSectionName = ""; - var lines = string.IsNullOrEmpty(text) ? Array.Empty() : text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); + var lines = string.IsNullOrEmpty(text) ? Array.Empty() : text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach(var line in lines) { diff --git a/src/BuildCheck.UnitTests/EditorConfigParser_Tests.cs b/src/BuildCheck.UnitTests/EditorConfigParser_Tests.cs index 17bd60abbd1..459b06ab28a 100644 --- a/src/BuildCheck.UnitTests/EditorConfigParser_Tests.cs +++ b/src/BuildCheck.UnitTests/EditorConfigParser_Tests.cs @@ -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(); @@ -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"); + } } From 0346115eaf8ce5f9d4b419ea47062ae5b6107b2d Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 1 Oct 2024 16:35:51 +0200 Subject: [PATCH 2/2] bump version --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index d2ea3fd097e..19451bded75 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 17.12.0release + 17.12.1release 17.11.4 15.1.0.0 preview