mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: expand nss myhostname fallback detection
Expand myhostname fallback detection to properly detect the local hostname in addition to other supported special names and suffixes. Fixes #17967 Change-Id: I1fe141fd9838b25886c08b6f2fd325e58be60457 Reviewed-on: https://go-review.googlesource.com/33550 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c77e80df6c
commit
4bd95702dd
3 changed files with 102 additions and 60 deletions
|
|
@ -334,15 +334,7 @@ func stringsHasSuffix(s, suffix string) bool {
|
|||
// stringsHasSuffixFold reports whether s ends in suffix,
|
||||
// ASCII-case-insensitively.
|
||||
func stringsHasSuffixFold(s, suffix string) bool {
|
||||
if len(suffix) > len(s) {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(suffix); i++ {
|
||||
if lowerASCII(suffix[i]) != lowerASCII(s[len(s)-len(suffix)+i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return len(s) >= len(suffix) && stringsEqualFold(s[len(s)-len(suffix):], suffix)
|
||||
}
|
||||
|
||||
// stringsHasPrefix is strings.HasPrefix. It reports whether s begins with prefix.
|
||||
|
|
@ -350,6 +342,20 @@ func stringsHasPrefix(s, prefix string) bool {
|
|||
return len(s) >= len(prefix) && s[:len(prefix)] == prefix
|
||||
}
|
||||
|
||||
// stringsEqualFold is strings.EqualFold, ASCII only. It reports whether s and t
|
||||
// are equal, ASCII-case-insensitively.
|
||||
func stringsEqualFold(s, t string) bool {
|
||||
if len(s) != len(t) {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(s); i++ {
|
||||
if lowerASCII(s[i]) != lowerASCII(t[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func readFull(r io.Reader) (all []byte, err error) {
|
||||
buf := make([]byte, 1024)
|
||||
for {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue