1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-11 12:02:35 +02:00

Fixed Ospath incorrectly detecting arbitrary colon as windows path.

This commit is contained in:
Taloth Saldono 2015-12-30 13:27:17 +01:00
parent 8753c232c7
commit 663d254ced
2 changed files with 14 additions and 2 deletions

View File

@ -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);

View File

@ -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)
{