dotnet / dotnet/aspnetcore

The manifest embedded file provider does not recognize the empty string as the root subpath.

Open
#40,053 1 comment 0 reactions 0 assignees View on GitHub
area-mvc
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

The `ManifestEmbeddedFileProvider` does not accept the empty string as the root subpath, but uses the current directory string `"."`.

```
new ManifestEmbeddedFileProvider(assembly, root).GetDirectoryContents("")
{Microsoft.Extensions.FileProviders.NotFoundDirectoryContents}
new ManifestEmbeddedFileProvider(assembly, root).GetDirectoryContents(".")
{Microsoft.Extensions.FileProviders.Embedded.Manifest.ManifestDirectoryContents}
```

### Expected Behavior

The `ManifestEmbeddedFileProvider` should work similarly to the `PhysicalFileProvider`, which uses the empty string as the root subpath.

```
new PhysicalFileProvider(root).GetDirectoryContents("")
{Microsoft.Extensions.FileProviders.Internal.PhysicalDirectoryContents}
new PhysicalFileProvider(root).GetDirectoryContents(".")
{Microsoft.Extensions.FileProviders.NotFoundDirectoryContents}
```

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

I understand that the physical file provider prohibits the use of the current and parent directory strings for security reasons (directory traversal) which do not apply to the manifest embedded file provider, but the difference means I cannot transparently use `GetDirectoryContents` on an `IFileProvider`; I _must_ determine the implementation type in order to use the method correctly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.