Fixed Ospath incorrectly detecting arbitrary colon as windows path.

pull/981/head
Taloth Saldono 9 years ago
parent 8753c232c7
commit 663d254ced

@ -24,6 +24,7 @@ namespace NzbDrone.Common.Test
[TestCase("/rooted/linux/path", OsPathKind.Unix)] [TestCase("/rooted/linux/path", OsPathKind.Unix)]
[TestCase("/", OsPathKind.Unix)] [TestCase("/", OsPathKind.Unix)]
[TestCase("linux/path", OsPathKind.Unix)] [TestCase("linux/path", OsPathKind.Unix)]
[TestCase(@"Castle:unrooted+linux+path", OsPathKind.Unknown)]
public void should_auto_detect_kind(string path, OsPathKind kind) public void should_auto_detect_kind(string path, OsPathKind kind)
{ {
var result = new OsPath(path); var result = new OsPath(path);
@ -94,6 +95,8 @@ namespace NzbDrone.Common.Test
[TestCase(@"rooted\windows\path")] [TestCase(@"rooted\windows\path")]
[TestCase(@"path")] [TestCase(@"path")]
[TestCase("linux/path")] [TestCase("linux/path")]
[TestCase(@"Castle:unrooted+linux+path")]
[TestCase(@"C:unrooted+linux+path")]
public void should_detect_unrooted_ospaths(string path) public void should_detect_unrooted_ospaths(string path)
{ {
var osPath = new OsPath(path); var osPath = new OsPath(path);

@ -44,7 +44,7 @@ namespace NzbDrone.Common.Disk
{ {
return OsPathKind.Unix; return OsPathKind.Unix;
} }
if (path.Contains(':') || path.Contains('\\')) if (HasWindowsDriveLetter(path) || path.Contains('\\'))
{ {
return OsPathKind.Windows; return OsPathKind.Windows;
} }
@ -55,6 +55,15 @@ namespace NzbDrone.Common.Disk
return OsPathKind.Unknown; return OsPathKind.Unknown;
} }
private static bool HasWindowsDriveLetter(string path)
{
if (path.Length < 2) return false;
if (!char.IsLetter(path[0]) || path[1] != ':') return false;
if (path.Length > 2 && path[2] != '\\' && path[2] != '/') return false;
return true;
}
private static string FixSlashes(string path, OsPathKind kind) private static string FixSlashes(string path, OsPathKind kind)
{ {
switch (kind) switch (kind)
@ -97,7 +106,7 @@ namespace NzbDrone.Common.Disk
{ {
if (IsWindowsPath) if (IsWindowsPath)
{ {
return _path.StartsWith(@"\\") || _path.Contains(':'); return _path.StartsWith(@"\\") || HasWindowsDriveLetter(_path);
} }
if (IsUnixPath) if (IsUnixPath)
{ {

Loading…
Cancel
Save