mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-22 10:25:46 +03:00
ext: Fix panic when URL path is empty
This commit is contained in:
parent
e9b9432da5
commit
76ec785e87
2 changed files with 2 additions and 1 deletions
|
@ -31,7 +31,7 @@ type Ext struct {
|
||||||
// ServeHTTP implements the middleware.Handler interface.
|
// ServeHTTP implements the middleware.Handler interface.
|
||||||
func (e Ext) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
func (e Ext) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
urlpath := strings.TrimSuffix(r.URL.Path, "/")
|
urlpath := strings.TrimSuffix(r.URL.Path, "/")
|
||||||
if path.Ext(urlpath) == "" && r.URL.Path[len(r.URL.Path)-1] != '/' {
|
if path.Ext(urlpath) == "" && len(r.URL.Path) > 0 && r.URL.Path[len(r.URL.Path)-1] != '/' {
|
||||||
for _, ext := range e.Extensions {
|
for _, ext := range e.Extensions {
|
||||||
if resourceExists(e.Root, urlpath+ext) {
|
if resourceExists(e.Root, urlpath+ext) {
|
||||||
r.URL.Path = urlpath + ext
|
r.URL.Path = urlpath + ext
|
||||||
|
|
|
@ -30,6 +30,7 @@ func TestExtensions(t *testing.T) {
|
||||||
{"/extensions_test/", []string{".html"}, "/extensions_test/"},
|
{"/extensions_test/", []string{".html"}, "/extensions_test/"},
|
||||||
{"/extensions_test", []string{".json"}, "/extensions_test"},
|
{"/extensions_test", []string{".json"}, "/extensions_test"},
|
||||||
{"/another_test", []string{".html"}, "/another_test"},
|
{"/another_test", []string{".html"}, "/another_test"},
|
||||||
|
{"", []string{".html"}, ""},
|
||||||
} {
|
} {
|
||||||
ex := Ext{
|
ex := Ext{
|
||||||
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
Next: middleware.HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
|
|
Loading…
Reference in a new issue