Update `StaticWebAssetsFileProvider NormalizePath` (#22418)

Skips an unnecessary null check.
This commit is contained in:
Huei Feng 2020-07-08 16:58:39 +08:00 committed by GitHub
parent 2e7359d8d3
commit 37a4457150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
private static string NormalizePath(string path)
{
path = path.Replace('\\', '/');
return path != null && path.StartsWith("/") ? path : "/" + path;
return path.StartsWith("/") ? path : "/" + path;
}
private bool StartsWithBasePath(string subpath, out PathString rest)

View File

@ -87,6 +87,20 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
// Assert
Assert.Empty(directory);
}
[Fact]
public void GetDirectoryContents_HandlersEmptyPath()
{
// Arrange
var provider = new StaticWebAssetsFileProvider("/_content",
Path.Combine(AppContext.BaseDirectory, "testroot", "wwwroot"));
// Act
var directory = provider.GetDirectoryContents("");
// Assert
Assert.True(directory.Exists);
}
[Fact]
public void GetDirectoryContents_HandlesWhitespaceInBase()