[Static Web Assets] Allow assets with empty base paths (#17414)
This commit is contained in:
parent
cba11d7e22
commit
b4d2f9aa52
|
|
@ -46,6 +46,11 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
|||
{
|
||||
var modifiedSub = NormalizePath(subpath);
|
||||
|
||||
if (BasePath == "/")
|
||||
{
|
||||
return InnerProvider.GetDirectoryContents(modifiedSub);
|
||||
}
|
||||
|
||||
if (StartsWithBasePath(modifiedSub, out var physicalPath))
|
||||
{
|
||||
return InnerProvider.GetDirectoryContents(physicalPath.Value);
|
||||
|
|
@ -67,6 +72,11 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
|||
{
|
||||
var modifiedSub = NormalizePath(subpath);
|
||||
|
||||
if (BasePath == "/")
|
||||
{
|
||||
return InnerProvider.GetFileInfo(subpath);
|
||||
}
|
||||
|
||||
if (!StartsWithBasePath(modifiedSub, out var physicalPath))
|
||||
{
|
||||
return new NotFoundFileInfo(subpath);
|
||||
|
|
|
|||
|
|
@ -117,6 +117,35 @@ namespace Microsoft.AspNetCore.Hosting.StaticWebAssets
|
|||
Assert.True(provider.GetFileInfo("/_content/Static Web Assets.txt").Exists);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDirectoryContents_HandlesEmptyBasePath()
|
||||
{
|
||||
// Arrange
|
||||
var provider = new StaticWebAssetsFileProvider("/",
|
||||
Path.Combine(AppContext.BaseDirectory, "testroot", "wwwroot"));
|
||||
|
||||
// Act
|
||||
var directory = provider.GetDirectoryContents("/Static Web/");
|
||||
|
||||
// Assert
|
||||
Assert.Collection(directory,
|
||||
file =>
|
||||
{
|
||||
Assert.Equal("Static Web.txt", file.Name);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaticWebAssetsFileProviderWithEmptyBasePath_FindsFile()
|
||||
{
|
||||
// Arrange & Act
|
||||
var provider = new StaticWebAssetsFileProvider("/",
|
||||
Path.Combine(AppContext.BaseDirectory, "testroot", "wwwroot"));
|
||||
|
||||
// Assert
|
||||
Assert.True(provider.GetFileInfo("/Static Web Assets.txt").Exists);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFileInfo_DoesNotMatch_IncompletePrefixSegments()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue