Skip to content
This repository has been archived by the owner on Nov 6, 2018. It is now read-only.

Commit

Permalink
Treat Path.GetFullPath exceptions as unknown files #201 #204
Browse files Browse the repository at this point in the history
  • Loading branch information
JunTaoLuo committed Jun 15, 2016
1 parent 258aa31 commit 6c86ff3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ private string GetFullPath(string path)
return null;
}

var fullPath = Path.GetFullPath(Path.Combine(Root, path));
string fullPath;
try
{
fullPath = Path.GetFullPath(Path.Combine(Root, path));
}
catch
{
return null;
}

if (!IsUnderneathRoot(fullPath))
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ public void GetFileInfoReturnsNotFoundFileInfoForEmptyPath()
}
}

public static TheoryData<string> InvalidPaths
{
get
{
return new TheoryData<string>
{
Path.Combine(". .", "file"),
Path.Combine(" ..", "file"),
Path.Combine(".. ", "file"),
Path.Combine(" .", "file"),
Path.Combine(". ", "file"),
};
}
}

[Theory]
[MemberData(nameof(InvalidPaths))]
public void GetFileInfoReturnsNonExistentFileInfoForIllegalPath(string path)
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var info = provider.GetFileInfo(path);
Assert.False(info.Exists);
}
}

[ConditionalFact]
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "Paths starting with / are considered relative.")]
[OSSkipCondition(OperatingSystems.MacOSX, SkipReason = "Paths starting with / are considered relative.")]
Expand Down Expand Up @@ -419,6 +445,17 @@ public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForNullPath()
}
}

[Theory]
[MemberData(nameof(InvalidPaths))]
public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForInvalidPath(string path)
{
using (var provider = new PhysicalFileProvider(Path.GetTempPath()))
{
var contents = provider.GetDirectoryContents(path);
Assert.IsType(typeof(NotFoundDirectoryContents), contents);
}
}

[Fact]
public void GetDirectoryContentsReturnsNotFoundDirectoryContentsForAbsolutePath()
{
Expand Down

0 comments on commit 6c86ff3

Please sign in to comment.