fileserver: append repeated `hide` subdirectives instead of overwriting (#7817)

Multiple `hide` subdirectives in a file_server Caddyfile block silently overwrote each other, so only the last one took effect. Append to the list instead, so repeated entries accumulate and imported snippets can compose with site-specific hides.
pull/7820/head
Luccin Masirika 2026-06-13 14:44:19 +02:00 committed by GitHub
parent 16235cced5
commit 39c9a85f80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,35 @@
:80
file_server {
hide first.txt
hide second.txt third.txt
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":80"
],
"routes": [
{
"handle": [
{
"handler": "file_server",
"hide": [
"first.txt",
"second.txt",
"third.txt",
"./Caddyfile"
]
}
]
}
]
}
}
}
}
}

View File

@ -91,10 +91,14 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
fsrv.FileSystem = d.Val() fsrv.FileSystem = d.Val()
case "hide": case "hide":
fsrv.Hide = d.RemainingArgs() hide := d.RemainingArgs()
if len(fsrv.Hide) == 0 { if len(hide) == 0 {
return d.ArgErr() return d.ArgErr()
} }
// Append so that repeated "hide" subdirectives accumulate
// instead of overwriting, which also lets imported snippets
// compose with site-specific hides.
fsrv.Hide = append(fsrv.Hide, hide...)
case "index": case "index":
fsrv.IndexNames = d.RemainingArgs() fsrv.IndexNames = d.RemainingArgs()