fileserver: Fix file
matcher with empty try_files
#4147
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #4146
If
TryFiles
is empty, we fill it withr.URL.Path
. In this case, this is/
. Then later, inprepareFilePath()
, we run the replacer (which turns{path}
into/
at that point) butfile
remains the original value (and the placeholder is still the placeholder there).So then
strings.HasSuffix(file, "/")
will befalse
for the placeholder, buttrue
for the emptyTryFiles
codepath, becausefile
was/
due to being set to the actual request value beforehand.This means that
suffix
becomes//
in that case, so aftersanitizedPathJoin
, it becomes./
, sostrictFileExists
'sstrings.HasSuffix(file, separator)
codepath will return true.I think we should change the
m.TryFiles == nil
codepath tom.TryFiles = []string{"{http.request.uri.path}"}
for consistency. (And maybe consider hoisting this toProvision
cause there's no point doing this on every request). I don't think this "optimization" of directly usingr.URL.Path
is so valuable, cause it causes this edgecase with directories.