Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore drive casing when comparing on windows platforms #73380

Merged
merged 19 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
using static Microsoft.CodeAnalysis.AnalyzerConfig;
using static Roslyn.Test.Utilities.TestHelpers;
Expand Down Expand Up @@ -63,30 +64,30 @@ public void ConfigWithEscapedValues()
{
var config = ParseConfigFile(@"is_global = true

[c:/\{f\*i\?le1\}.cs]
[C:/\{f\*i\?le1\}.cs]
build_metadata.Compile.ToRetrieve = abc123

[c:/f\,ile\#2.cs]
[C:/f\,ile\#2.cs]
build_metadata.Compile.ToRetrieve = def456

[c:/f\;i\!le\[3\].cs]
[C:/f\;i\!le\[3\].cs]
build_metadata.Compile.ToRetrieve = ghi789
");

var namedSections = config.NamedSections;
Assert.Equal("c:/\\{f\\*i\\?le1\\}.cs", namedSections[0].Name);
Assert.Equal("C:/\\{f\\*i\\?le1\\}.cs", namedSections[0].Name);
AssertEx.Equal(
new[] { KeyValuePair.Create("build_metadata.compile.toretrieve", "abc123") },
namedSections[0].Properties
);

Assert.Equal("c:/f\\,ile\\#2.cs", namedSections[1].Name);
Assert.Equal("C:/f\\,ile\\#2.cs", namedSections[1].Name);
AssertEx.Equal(
new[] { KeyValuePair.Create("build_metadata.compile.toretrieve", "def456") },
namedSections[1].Properties
);

Assert.Equal("c:/f\\;i\\!le\\[3\\].cs", namedSections[2].Name);
Assert.Equal("C:/f\\;i\\!le\\[3\\].cs", namedSections[2].Name);
AssertEx.Equal(
new[] { KeyValuePair.Create("build_metadata.compile.toretrieve", "ghi789") },
namedSections[2].Properties
Expand Down Expand Up @@ -118,14 +119,15 @@ public void CanGetSectionsWithSpecialCharacters()
[ConditionalFact(typeof(WindowsOnly))]
public void CanGetSectionsWithDifferentDriveCasing()
{
var config = ParseConfigFile(@"is_global = true
var config = Parse(@"is_global = true
build_metadata.compile.toretrieve = global

[c:\goo\file.cs]
[c:/goo/file.cs]
build_metadata.compile.toretrieve = abc123

[C:\goo\other.cs]
[C:/goo/other.cs]
build_metadata.compile.toretrieve = def456
");
", pathToFile: @"C:/.editorconfig");

var set = AnalyzerConfigSet.Create(ImmutableArray.Create(config));

Expand All @@ -140,6 +142,12 @@ public void CanGetSectionsWithDifferentDriveCasing()

sectionOptions = set.GetOptionsForSourcePath(@"c:\goo\other.cs");
Assert.Equal("def456", sectionOptions.AnalyzerOptions["build_metadata.compile.toretrieve"]);

sectionOptions = set.GetOptionsForSourcePath(@"c:\global.cs");
Assert.Equal("global", sectionOptions.AnalyzerOptions["build_metadata.compile.toretrieve"]);

sectionOptions = set.GetOptionsForSourcePath(@"C:\global.cs");
Assert.Equal("global", sectionOptions.AnalyzerOptions["build_metadata.compile.toretrieve"]);
}

[ConditionalFact(typeof(WindowsOnly))]
Expand Down Expand Up @@ -2266,6 +2274,8 @@ public void GlobalConfigOptionsAreEmptyWhenNoGlobalConfig()
[InlineData("", true)] // only true because [] isn't a valid editorconfig section name either and thus never gets parsed
public void GlobalConfigIssuesWarningWithInvalidSectionNames(string sectionName, bool isValid)
{
sectionName = PathUtilities.NormalizeDriveLetter(sectionName);
ryzngard marked this conversation as resolved.
Show resolved Hide resolved

var configs = ArrayBuilder<AnalyzerConfig>.GetInstance();
configs.Add(Parse($@"
is_global = true
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/Core/Portable/CommandLine/AnalyzerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ public static AnalyzerConfig Parse(SourceText text, string? pathToFile)
// Add the last section
addNewSection();

// Normalize the path to file the same way we named sections are done
ryzngard marked this conversation as resolved.
Show resolved Hide resolved
pathToFile = PathUtilities.NormalizeDriveLetter(pathToFile);

return new AnalyzerConfig(globalSection!, namedSectionBuilder.ToImmutable(), pathToFile);

void addNewSection()
Expand Down