peteraritchie / LongPath

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

Path.GetUncRootLength does not support paths containing forward-slashes #41

Closed herebebeasties closed 7 years ago

herebebeasties commented 8 years ago

In the Path class:

private static int GetUncRootLength(string path)
{
    var components = path.Split(new[] { DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
    var root = string.Format(@"\\{0}\{1}\", components[0], components[1]);
    return root.Length;
}

...throws an index out of bounds exception if you give it a path containing only forward-slashes (AltDirectorySeparatorChar). I think the Split should be for either. This occurs if you try to call Directory.Create() with a long path (i.e. > MAX_PATH chars) with forward-slashes, for example.

(Apologies - I'm behind an office firewall where I can't make a pull request / tests for this. :-( )

peteraritchie commented 8 years ago

I can't seem to reproduce this with a long path. I created a test with the following body:

var tempLongPathFilename = 
    Path.Combine(longPathDirectory, Path.GetRandomFileName())
    .Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
var di = new DirectoryInfo(tempLongPathFilename);
di.Create();
Assert.IsTrue(di.Exists);
di.Delete(recursive: true);

Is there some other information you can give me to help me reproduce this?

herebebeasties commented 8 years ago

It's possible that head doesn't reproduce this - I have a slightly old version. Will update and let you know (sorry - I realise people like me who aren't on the latest version are a pain in the ass for bug reports, but I looked at the newer code and thought it'd behave in the same way).