mirror of
https://github.com/Radarr/Radarr
synced 2024-12-31 20:35:37 +00:00
Fixed Ospath incorrectly detecting arbitrary colon as windows path.
This commit is contained in:
parent
8753c232c7
commit
663d254ced
2 changed files with 14 additions and 2 deletions
|
@ -24,6 +24,7 @@ public class OsPathFixture : TestBase
|
||||||
[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 @@ public void should_detect_rooted_ospaths(string path)
|
||||||
[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 @@ private static OsPathKind DetectPathKind(string path)
|
||||||
{
|
{
|
||||||
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 @@ private static OsPathKind DetectPathKind(string path)
|
||||||
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 @@ public bool IsRooted
|
||||||
{
|
{
|
||||||
if (IsWindowsPath)
|
if (IsWindowsPath)
|
||||||
{
|
{
|
||||||
return _path.StartsWith(@"\\") || _path.Contains(':');
|
return _path.StartsWith(@"\\") || HasWindowsDriveLetter(_path);
|
||||||
}
|
}
|
||||||
if (IsUnixPath)
|
if (IsUnixPath)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue