Skip to content

Commit 37a4457

Browse files
authored
Update StaticWebAssetsFileProvider NormalizePath (#22418)
Skips an unnecessary null check.
1 parent 2e7359d commit 37a4457

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsFileProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public IChangeToken Watch(string filter)
9696
private static string NormalizePath(string path)
9797
{
9898
path = path.Replace('\\', '/');
99-
return path != null && path.StartsWith("/") ? path : "/" + path;
99+
return path.StartsWith("/") ? path : "/" + path;
100100
}
101101

102102
private bool StartsWithBasePath(string subpath, out PathString rest)

src/Hosting/Hosting/test/StaticWebAssets/StaticWebAssetsFileProviderTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ public void GetDirectoryContents_PartialMatchFails(string requestedUrl)
8787
// Assert
8888
Assert.Empty(directory);
8989
}
90+
91+
[Fact]
92+
public void GetDirectoryContents_HandlersEmptyPath()
93+
{
94+
// Arrange
95+
var provider = new StaticWebAssetsFileProvider("/_content",
96+
Path.Combine(AppContext.BaseDirectory, "testroot", "wwwroot"));
97+
98+
// Act
99+
var directory = provider.GetDirectoryContents("");
100+
101+
// Assert
102+
Assert.True(directory.Exists);
103+
}
90104

91105
[Fact]
92106
public void GetDirectoryContents_HandlesWhitespaceInBase()

0 commit comments

Comments
 (0)