Skip to content

Commit 33c88bd

Browse files
authored
refactor: replace HasPrefix+TrimPrefix with CutPrefix (#7095)
Signed-off-by: gopherorg <[email protected]>
1 parent 11c6dae commit 33c88bd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

modules/caddyevents/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ func (app *App) Emit(ctx caddy.Context, eventName string, data map[string]any) c
249249
return e.Data, true
250250
}
251251

252-
if strings.HasPrefix(key, "event.data.") {
253-
key = strings.TrimPrefix(key, "event.data.")
252+
if after, ok0 := strings.CutPrefix(key, "event.data."); ok0 {
253+
key = after
254254
if val, ok := e.Data[key]; ok {
255255
return val, true
256256
}

modules/caddyhttp/fileserver/staticfiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,11 +684,11 @@ func fileHidden(filename string, hide []string) bool {
684684
return true
685685
}
686686
}
687-
} else if strings.HasPrefix(filename, h) {
687+
} else if after, ok := strings.CutPrefix(filename, h); ok {
688688
// if there is a separator in h, and filename is exactly
689689
// prefixed with h, then we can do a prefix match so that
690690
// "/foo" matches "/foo/bar" but not "/foobar".
691-
withoutPrefix := strings.TrimPrefix(filename, h)
691+
withoutPrefix := after
692692
if strings.HasPrefix(withoutPrefix, separator) {
693693
return true
694694
}

0 commit comments

Comments
 (0)