diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-04-14 16:11:46 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-04-14 16:11:46 -0600 |
commit | 829e36d535cf5bbff7cf0f510608e6fca956cec4 (patch) | |
tree | e7376af9652a076f964baf76f9c01ee0f54d050b /caddyconfig/httpcaddyfile/addresses.go | |
parent | 2609a728936775377ae14834f9073f1bdc2f7601 (diff) |
httpcaddyfile: Don't lowercase placeholder contents (fixes #3264)
Diffstat (limited to 'caddyconfig/httpcaddyfile/addresses.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/addresses.go | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/caddyconfig/httpcaddyfile/addresses.go b/caddyconfig/httpcaddyfile/addresses.go index e40f30c..51411a9 100644 --- a/caddyconfig/httpcaddyfile/addresses.go +++ b/caddyconfig/httpcaddyfile/addresses.go @@ -20,6 +20,7 @@ import ( "reflect" "strconv" "strings" + "unicode" "github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" @@ -333,8 +334,8 @@ func (a Address) Normalize() Address { return Address{ Original: a.Original, - Scheme: strings.ToLower(a.Scheme), - Host: strings.ToLower(host), + Scheme: lowerExceptPlaceholders(a.Scheme), + Host: lowerExceptPlaceholders(host), Port: a.Port, Path: path, } @@ -361,3 +362,31 @@ func (a Address) Key() string { } return res } + +// lowerExceptPlaceholders lowercases s except within +// placeholders (substrings in non-escaped '{ }' spans). +// See https://github.com/caddyserver/caddy/issues/3264 +func lowerExceptPlaceholders(s string) string { + var sb strings.Builder + var escaped, inPlaceholder bool + for _, ch := range s { + if ch == '\\' && !escaped { + escaped = true + sb.WriteRune(ch) + continue + } + if ch == '{' && !escaped { + inPlaceholder = true + } + if ch == '}' && inPlaceholder && !escaped { + inPlaceholder = false + } + if inPlaceholder { + sb.WriteRune(ch) + } else { + sb.WriteRune(unicode.ToLower(ch)) + } + escaped = false + } + return sb.String() +} |