peteraritchie / LongPath

drop-in library to support long paths in .NET
GNU Lesser General Public License v3.0
112 stars 43 forks source link

Long UNC pathname containing forward-slash (/) path separators is not normalised correctly #97

Open MarkCranness opened 1 year ago

MarkCranness commented 1 year ago

This long path:

\\server\share\Folder\Folder\Folder\11111111-2222-3333-4444-555555555555\Folder\Clients/1234/1\11111 - FW Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, quis nostrud.msg

... is normalised to:

\\?\UNC\server\share\Folder\Folder\Folder\11111111-2222-3333-4444-555555555555\Folder\Clients/1234/1\11111 - FW Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, quis nostrud.msg

(Note: embedded "/" path separators at "\Clients/1234/1\", which cause Windows errors.)

(If instead the pathname starts with a drive letter, then the "/" path separators are changed to "\" characters, and the same should happen with UNC pathnames.)

A fix might be to change lines 110 thru 111 of Path.cs like so:

var rootPathLength = 3 + uri.Host.Length; maxPathLimit -= rootPathLength; path = path.Replace(AltDirectorySeparatorChar, DirectorySeparatorChar); }