mirror of
https://github.com/fergalmoran/Readarr.git
synced 2026-01-09 10:16:41 +00:00
Fixed Ospath incorrectly detecting arbitrary colon as windows path.
This commit is contained in:
@@ -24,6 +24,7 @@ namespace NzbDrone.Common.Test
|
||||
[TestCase("/rooted/linux/path", OsPathKind.Unix)]
|
||||
[TestCase("/", OsPathKind.Unix)]
|
||||
[TestCase("linux/path", OsPathKind.Unix)]
|
||||
[TestCase(@"Castle:unrooted+linux+path", OsPathKind.Unknown)]
|
||||
public void should_auto_detect_kind(string path, OsPathKind kind)
|
||||
{
|
||||
var result = new OsPath(path);
|
||||
@@ -94,6 +95,8 @@ namespace NzbDrone.Common.Test
|
||||
[TestCase(@"rooted\windows\path")]
|
||||
[TestCase(@"path")]
|
||||
[TestCase("linux/path")]
|
||||
[TestCase(@"Castle:unrooted+linux+path")]
|
||||
[TestCase(@"C:unrooted+linux+path")]
|
||||
public void should_detect_unrooted_ospaths(string path)
|
||||
{
|
||||
var osPath = new OsPath(path);
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace NzbDrone.Common.Disk
|
||||
{
|
||||
return OsPathKind.Unix;
|
||||
}
|
||||
if (path.Contains(':') || path.Contains('\\'))
|
||||
if (HasWindowsDriveLetter(path) || path.Contains('\\'))
|
||||
{
|
||||
return OsPathKind.Windows;
|
||||
}
|
||||
@@ -55,6 +55,15 @@ namespace NzbDrone.Common.Disk
|
||||
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)
|
||||
{
|
||||
switch (kind)
|
||||
@@ -97,7 +106,7 @@ namespace NzbDrone.Common.Disk
|
||||
{
|
||||
if (IsWindowsPath)
|
||||
{
|
||||
return _path.StartsWith(@"\\") || _path.Contains(':');
|
||||
return _path.StartsWith(@"\\") || HasWindowsDriveLetter(_path);
|
||||
}
|
||||
if (IsUnixPath)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user