@marcel91200 / caddy Mirror · read-only / commits / 69f22e24
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 02:15 UTC

fileserver: return an empty listing for offsets past the end (#8213)

Signed-off-by: Shane Jonas <jonas.shane@gmail.com>

Shane committed Oct 13, 2026 at 11:36 UTC 69f22e244296dc33c96e3d6ca4a4bdb2b2680e76
2 files changed +10 -2
modules/caddyhttp/fileserver/browsetplcontext.go
+2 -2
@@ -264,8 +264,8 @@ func (l *browseTemplateContext) applySortAndLimit(sortParam, orderParam, limitPa
264
265 if offsetParam != "" {
266 offset, _ := strconv.Atoi(offsetParam)
267 - if offset > 0 && offset <= len(l.Items) {
268 - l.Items = l.Items[offset:]
267 + if offset > 0 {
268 + l.Items = l.Items[min(offset, len(l.Items)):]
269 l.Offset = offset
270 }
271 }
modules/caddyhttp/fileserver/browsetplcontext_test.go
+8
@@ -24,6 +24,14 @@ import (
24 "github.com/caddyserver/caddy/v2"
25 )
26
27 +func TestBrowseOffsetPastEnd(t *testing.T) {
28 + listing := browseTemplateContext{Items: []fileInfo{{Name: "a"}, {Name: "b"}}}
29 + listing.applySortAndLimit(sortByName, sortOrderAsc, "1", "3")
30 + if len(listing.Items) != 0 {
31 + t.Errorf("got %d items past the end; want none", len(listing.Items))
32 + }
33 +}
34 +
35 func TestBreadcrumbs(t *testing.T) {
36 testdata := []struct {
37 path string