-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add public methods that remove path redundant segments #2187
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
Conversation
src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs
Outdated
Show resolved
Hide resolved
|
The purpose of |
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/PathInternal.cs
Outdated
Show resolved
Hide resolved
|
I'll close this issue while it's in draft mode. I'll reopen when the unit tests are ready. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ValueStringBuilder is meant to be used with stackallocated buffer for sizes up to certain limit. Getting a pooled buffer has too much overhead for small buffers.
src/libraries/System.Runtime.Extensions/tests/System/IO/Path.RemoveRedundantSegments.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JeremyKuhne - I'm investigating these tests where I put a comment next to them, because their behavior was slightly different than expected.
I also noticed the resulting path is different in Windows than in Unix, because of the separator char used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I talked with Jeremy about the expected behavior on each edge case. I am adding tests to verify them.
|
Currently blocked by a bug I found in |
…rt type 'string' to 'System.ReadOnlySpan<char>'.
…he span overloads of GetPathRoot and IsPathFullyQualified inside PathInternal.
| if (string.IsNullOrEmpty(path)) | ||
| return path; | ||
|
|
||
| Span<char> destination = stackalloc char[path.Length]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unbounded stackallocs are prohibited in dotnet/runtime libraries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub I don't see record of a discussion about trying to catch this with an analyzer. It's not generally possible to be sure (either way) whether it's unbounded. But an analyzer that forced a pattern of passing a constant value would be doable.
Looking at all our stackallocs, almost all of them already pass a constant directly or via a constant field or local. The few exceptions are not self evidently safe by eyeball, eg.,
private static unsafe int EncryptDecryptHelper(OP op, ISSPIInterface secModule, SafeDeleteContext context, Span<SecurityBuffer> input, uint sequenceNumber)
{
Interop.SspiCli.SecBufferDesc sdcInOut = new Interop.SspiCli.SecBufferDesc(input.Length);
Span<Interop.SspiCli.SecBuffer> unmanagedBuffer = stackalloc Interop.SspiCli.SecBuffer[input.Length];and it would be easy for one of them to be wrong. Would it be reasonable to have an analyzer that required them to be rewritten in constant terms, or at least something the analyzer could recognize like
Span<Interop.SspiCli.SecBuffer> unmanagedBuffer = stackalloc Interop.SspiCli.SecBuffer[Math.Min(input.Length, BufferSize)];There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to #35382
|
I'll close this while I address the Unix failures. |
Fixes #2162