mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Fixed Ospath incorrectly detecting arbitrary colon as windows path.
This commit is contained in:
parent
8753c232c7
commit
663d254ced
@ -24,6 +24,7 @@ public class OsPathFixture : TestBase
|
||||
[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 @@ public void should_detect_rooted_ospaths(string path)
|
||||
[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 @@ private static OsPathKind DetectPathKind(string path)
|
||||
{
|
||||
return OsPathKind.Unix;
|
||||
}
|
||||
if (path.Contains(':') || path.Contains('\\'))
|
||||
if (HasWindowsDriveLetter(path) || path.Contains('\\'))
|
||||
{
|
||||
return OsPathKind.Windows;
|
||||
}
|
||||
@ -55,6 +55,15 @@ private static OsPathKind DetectPathKind(string path)
|
||||
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 @@ public bool IsRooted
|
||||
{
|
||||
if (IsWindowsPath)
|
||||
{
|
||||
return _path.StartsWith(@"\\") || _path.Contains(':');
|
||||
return _path.StartsWith(@"\\") || HasWindowsDriveLetter(_path);
|
||||
}
|
||||
if (IsUnixPath)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user