Skip to content

Ensure source paths are comparable with editorconfig directory paths#73100

Merged
jjonescz merged 3 commits intodotnet:mainfrom
jjonescz:72657-DoubleSlash
May 2, 2024
Merged

Ensure source paths are comparable with editorconfig directory paths#73100
jjonescz merged 3 commits intodotnet:mainfrom
jjonescz:72657-DoubleSlash

Conversation

@jjonescz
Copy link
Member

@jjonescz jjonescz commented Apr 19, 2024

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

@ghost ghost 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
Member 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 force-pushed the 72657-DoubleSlash branch from 087d429 to 7ba5450 Compare April 22, 2024 09:27
@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
Member 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
Member Author

@dotnet/roslyn-compiler for reviews, thanks

@jaredpar
Copy link
Member

@RikkiGibson, @chsienki PTAL

}

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

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
Member

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
@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
  ...
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
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

Development

Successfully merging this pull request may close these issues.

Editorconfig in nuget package is not respected if slashes in source file path do not exactly match slashes in .editorconfig path

5 participants