-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Fix creating subdirectories under directories with trailing separators #30293
Conversation
This broke with dotnet#27810. Reworked the logic in an attempt to be clearer and added test cases. This addresses #30283.
pjanotti
left a comment
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 guess that there are other tests that already cover the case when there is no directory separator on the end of the path. LGTM.
| ReadOnlySpan<char> trimmedCurrentPath = PathInternal.TrimEndingDirectorySeparator(FullPath.AsSpan()); | ||
|
|
||
| // We want to make sure the requested directory is actually under the subdirectory. | ||
| if (!trimmedNewPath.StartsWith(trimmedCurrentPath, PathInternal.StringComparison) |
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 found it easier to grok if I flip it around, up to you
// Make sure the requested directory is actually under the subdirectory.
if (trimmedNewPath.StartsWith(trimmedCurrentPath, PathInternal.StringComparison)
{
// Note we must also check the first character after the current path is a slash.
// Otherwise passing "c:\foo" and "..\foobar", which would produce a new path of "c:\foobar", would be allowed.
if ((trimmedNewPath.Length == trimmedCurrentPath.Length) || PathInternal.IsDirectorySeparator(newPath[trimmedCurrentPath.Length])
{
FileSystem.CreateDirectory(newPath);
return new DirectoryInfo(newPath);
}
}
throw new ArgumentException(SR.Format(SR.Argument_InvalidSubPath, path, FullPath), nameof(path));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 found it easier to grok if I flip it around
I agree- it reduces the negatives. Updating.
(Reduces the number of nots.)
|
@JeremyKuhne it's not super obvious (https://github.com/dotnet/core-eng/issues/3107) but your test failure is in NETFX. The new test is not failing on NETFX as expected. Perhaps that means we need to be more lenient in .NET Core. |
|
Cross check leg is optional right now. |
dotnet#30293) * Fix creating subdirectories under directories with trailing separators This broke with dotnet#27810. Reworked the logic in an attempt to be clearer and added test cases. This addresses #30283. * Flip the logic to make it a little easier to follow. (Reduces the number of nots.) * Skip new test on desktop
#30293) * Fix creating subdirectories under directories with trailing separators This broke with #27810. Reworked the logic in an attempt to be clearer and added test cases. This addresses #30283. * Flip the logic to make it a little easier to follow. (Reduces the number of nots.) * Skip new test on desktop
|
This PR was fixed in master - hence 3.0. The change was ported into release/2.1 branch in PR #30367. |
dotnet/corefx#30293) * Fix creating subdirectories under directories with trailing separators This broke with dotnet/corefx#27810. Reworked the logic in an attempt to be clearer and added test cases. This addresses dotnet/corefx#30283. * Flip the logic to make it a little easier to follow. (Reduces the number of nots.) * Skip new test on desktop Commit migrated from dotnet/corefx@4a6f54e
This broke with #27810. Reworked the logic in an attempt to be clearer and added test cases.
This addresses #30283.