Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@JeremyKuhne
Copy link
Member

This broke with #27810. Reworked the logic in an attempt to be clearer and added test cases.

This addresses #30283.

This broke with dotnet#27810. Reworked the logic in an attempt to be clearer and added test cases.

This addresses #30283.
@JeremyKuhne JeremyKuhne added this to the 2.1.x milestone Jun 11, 2018
@JeremyKuhne JeremyKuhne self-assigned this Jun 11, 2018
Copy link
Contributor

@pjanotti pjanotti left a 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)
Copy link
Member

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));

Copy link
Member Author

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.

@danmoseley
Copy link
Member

@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.

@danmoseley
Copy link
Member

Cross check leg is optional right now.

@danmoseley danmoseley merged commit 4a6f54e into dotnet:master Jun 13, 2018
JeremyKuhne added a commit to JeremyKuhne/corefx that referenced this pull request Jun 13, 2018
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
@JeremyKuhne JeremyKuhne deleted the fix30283 branch June 13, 2018 20:33
JeremyKuhne added a commit that referenced this pull request Jun 27, 2018
#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
@karelz karelz modified the milestones: 2.1.x, 3.0 Jul 8, 2018
@karelz
Copy link
Member

karelz commented Jul 8, 2018

This PR was fixed in master - hence 3.0. The change was ported into release/2.1 branch in PR #30367.

picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants