From c22799fa12c99932fc4620fce2dc0994567a52af Mon Sep 17 00:00:00 2001 From: tjp Date: Tue, 14 Nov 2023 09:39:53 -0700 Subject: bugfixes from the Protocol refactor --- gopher/gophermap/extended.go | 9 +++++++-- gopher/gophermap/listdir.go | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'gopher/gophermap') diff --git a/gopher/gophermap/extended.go b/gopher/gophermap/extended.go index f2ca3fc..910adc0 100644 --- a/gopher/gophermap/extended.go +++ b/gopher/gophermap/extended.go @@ -307,7 +307,7 @@ func ExtendMiddleware(fsroot, urlroot string, settings *FileSystemSettings) sr.M return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response { response := handler.Handle(ctx, request) - if !settings.ParseExtended || response.Status != gopher.MenuType { + if settings == nil || response == nil || !settings.ParseExtended || response.Status != gopher.MenuType { return response } @@ -322,7 +322,12 @@ func ExtendMiddleware(fsroot, urlroot string, settings *FileSystemSettings) sr.M fpath = strings.Trim(fpath, "/") fpath = filepath.Join(fsroot, fpath) - doc, _, err := edoc.Compatible(filepath.Dir(fpath), *settings) + cwd := fpath + if !strings.HasSuffix(request.Path, "/") { + cwd = filepath.Dir(cwd) + } + + doc, _, err := edoc.Compatible(cwd, *settings) if err != nil { return gopher.Error(err).Response() } diff --git a/gopher/gophermap/listdir.go b/gopher/gophermap/listdir.go index a2c5214..30d7790 100644 --- a/gopher/gophermap/listdir.go +++ b/gopher/gophermap/listdir.go @@ -28,6 +28,7 @@ func listDir(dir string, location *url.URL, settings FileSystemSettings, hidden for _, entry := range contents { name := entry.Name() + fpath := filepath.Join(dir, name) inf, err := entry.Info() if err != nil { @@ -52,7 +53,7 @@ func listDir(dir string, location *url.URL, settings FileSystemSettings, hidden } else if c, ok := extensions[name]; ok { code = c } else { - code = gopher.GuessItemType(name) + code = gopher.GuessItemType(fpath) } } -- cgit v1.2.3