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

Ensure source paths are comparable with editorconfig directory paths #73100

Merged
merged 3 commits into from May 2, 2024

Conversation

jjonescz
Copy link
Contributor

@jjonescz jjonescz commented Apr 19, 2024

Fixes #72657 as suggested in comment #72657 (comment).

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 19, 2024
normalizedDirectory = PathUtilities.NormalizeWithForwardSlash(normalizedDirectory);
normalizedDirectory = PathUtilities.ExpandAbsolutePathWithRelativeParts(normalizedDirectory);

var normalizedPath = PathUtilities.EnsureTrailingSeparator(normalizedDirectory) + Path.GetFileName(sourcePath);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EnsureTrailingSeparator call is going to add an OS specific separator while I believe this code path expects to have forward slashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnsureTrailingSeparator looks for existing slashes in the path and adds a consistent one, so that shouldn't be a problem.

@jjonescz jjonescz marked this pull request as ready for review April 22, 2024 10:32
@jjonescz jjonescz requested a review from a team as a code owner April 22, 2024 10:32
/// <summary>
/// Replaces all sequences of '\' or '/' with a single '/' but preserves UNC prefix '//'.
/// </summary>
public static string CollapseWithForwardSlash(string p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static string CollapseWithForwardSlash(string p)
public static string CollapseWithForwardSlash(ReadOnlySpan<char> p)

Consider using a ReadOnlySpan<char>. Makes it easier for future changes that are span related to call this API.

{
sb.Append('/');
}
wasDirectorySeparator = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider an input string of a\\\b. That would result in an output of a/b Is that intended here? If so let's make sure there is a unit test for that case.

Copy link
Contributor Author

@jjonescz jjonescz Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's intended, will add a test, thanks.

@jjonescz
Copy link
Contributor Author

@dotnet/roslyn-compiler for reviews, thanks

@jaredpar
Copy link
Member

@RikkiGibson, @chsienki PTAL

@@ -210,6 +210,63 @@ class C
Assert.Null(cmd.AnalyzerOptions);
}

[Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/72657")]
public void AnalyzerConfig_DoubleSlash(bool doubleSlash1, bool doubleSlash2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider naming these parameters based on which element we are introducing double slashes for, e.g. bool doubleSlashAnalyzerConfig, bool doubleSlashSource

[InlineData("/a/b/c/", "/a/b/c//")]
[InlineData("/a/b/c//", "/a/b/c//")]
[InlineData("/a/b//c/", "/a/b///c/")]
public void EditorConfigToDiagnostics_DoubleSlash(string prefix1, string prefix2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider naming these parameters based on how each prefix is being used.

@jjonescz jjonescz enabled auto-merge (squash) May 2, 2024 08:21
@jjonescz jjonescz merged commit fa7ece1 into dotnet:main May 2, 2024
24 checks passed
@jjonescz jjonescz deleted the 72657-DoubleSlash branch May 2, 2024 09:22
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 2, 2024
333fred added a commit to 333fred/roslyn that referenced this pull request May 2, 2024
* upstream/main: (1047 commits)
  Ensure source paths are comparable with editorconfig directory paths (dotnet#73100)
  Lower drop retention from 10 years to 3 months (dotnet#73190)
  Move
  fix
  restore code
  remove
  simplify
  simplify
  Move off of map
  Simplify tests
  Simplify tests
  Simplify tests
  Simplify tests
  Simplify tests
  simplify
  finish
  Simplify
  Fix
  Finish
  Remove dispose support
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
4 participants