mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 21:53:48 +03:00
Replace strings.Index with strings.Cut (#4932)
This commit is contained in:
parent
2642bd72b7
commit
d26559316f
3 changed files with 6 additions and 9 deletions
|
@ -408,11 +408,8 @@ func parseEnvFile(envInput io.Reader) (map[string]string, error) {
|
|||
}
|
||||
|
||||
// remove any trailing comment after value
|
||||
if commentStart := strings.Index(val, "#"); commentStart > 0 {
|
||||
before := val[commentStart-1]
|
||||
if before == '\t' || before == ' ' {
|
||||
val = strings.TrimRight(val[:commentStart], " \t")
|
||||
}
|
||||
if commentStart, _, found := strings.Cut(val, "#"); found {
|
||||
val = strings.TrimRight(commentStart, " \t")
|
||||
}
|
||||
|
||||
// quoted value: support newlines
|
||||
|
|
|
@ -658,8 +658,8 @@ func (h Handler) addForwardedHeaders(req *http.Request) error {
|
|||
|
||||
// Client IP may contain a zone if IPv6, so we need
|
||||
// to pull that out before parsing the IP
|
||||
if idx := strings.IndexByte(clientIP, '%'); idx >= 0 {
|
||||
clientIP = clientIP[:idx]
|
||||
if before, _, found := strings.Cut(clientIP, "%"); found {
|
||||
clientIP = before
|
||||
}
|
||||
ip := net.ParseIP(clientIP)
|
||||
if ip == nil {
|
||||
|
|
|
@ -194,10 +194,10 @@ func (rewr Rewrite) Rewrite(r *http.Request, repl *caddy.Replacer) bool {
|
|||
|
||||
// before continuing, we need to check if a query string
|
||||
// snuck into the path component during replacements
|
||||
if quPos := strings.Index(newPath, "?"); quPos > -1 {
|
||||
if before, after, found := strings.Cut(newPath, "?"); found {
|
||||
// recompute; new path contains a query string
|
||||
var injectedQuery string
|
||||
newPath, injectedQuery = newPath[:quPos], newPath[quPos+1:]
|
||||
newPath, injectedQuery = before, after
|
||||
// don't overwrite explicitly-configured query string
|
||||
if query == "" {
|
||||
query = injectedQuery
|
||||
|
|
Loading…
Reference in a new issue