aspnet / StaticFiles

[Archived] Middleware for handling requests for file system resources including files and directories. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
114 stars 72 forks source link

fix unicode url 404 error #256

Closed newbienewbie closed 6 years ago

newbienewbie commented 6 years ago

When serving a static directory whose path string contains unicode codes , let's say

The DefaultFileMiddlware gets the directory by var dirContents = _fileProvider.GetDirectoryContents(subpath.Value); . And now when we check whether the path of blog/categories/大道/ exists as below :

https://github.com/aspnet/StaticFiles/blob/4c8df8e5a4e3abe5e7db51685dbd892d160c1e35/src/Microsoft.AspNetCore.StaticFiles/DefaultFilesMiddleware.cs#L69

The result will be true .

However , when coming into the default index.html , the DefaultFileMiddlware checks the file path by :

var file = _fileProvider.GetFileInfo(subpath + defaultFile);

Here the subpath is often urlencoded , so the file path will be something as below :

"blog\\categories\\%E5%A4%A7%E9%81%93\\index.html"

As a result , file.Exists will return false .

Tratcher commented 6 years ago

Interesting find. Can you: A) File an issue with these details, issues are easier to track. B) Add a test for this scenario. C) Rebase onto the release/2.2 branch, that's our upcoming release and this would be a good thing to include.

If you can't take care of these in a few days then we'll see about getting someone assigned to it.

newbienewbie commented 6 years ago

@Tratcher Hi, I've created a new issue here . I'll add tests for this scenario .

poke commented 6 years ago

Superseded by #257.