mirror of
https://github.com/minio/minio.git
synced 2025-11-20 01:50:24 -05:00
fix: allow updated domain names in federation (#11365)
additionally also disallow overlapping domain names
This commit is contained in:
73
cmd/utils.go
73
cmd/utils.go
@@ -665,37 +665,56 @@ func restQueries(keys ...string) []string {
|
||||
return accumulator
|
||||
}
|
||||
|
||||
// lcp finds the longest common prefix of the input strings.
|
||||
// It compares by bytes instead of runes (Unicode code points).
|
||||
// It's up to the caller to do Unicode normalization if desired
|
||||
// (e.g. see golang.org/x/text/unicode/norm).
|
||||
func lcp(l []string) string {
|
||||
// Special cases first
|
||||
switch len(l) {
|
||||
case 0:
|
||||
// Suffix returns the longest common suffix of the provided strings
|
||||
func lcpSuffix(strs []string) string {
|
||||
return lcp(strs, false)
|
||||
}
|
||||
|
||||
func lcp(strs []string, pre bool) string {
|
||||
// short-circuit empty list
|
||||
if len(strs) == 0 {
|
||||
return ""
|
||||
case 1:
|
||||
return l[0]
|
||||
}
|
||||
// LCP of min and max (lexigraphically)
|
||||
// is the LCP of the whole set.
|
||||
min, max := l[0], l[0]
|
||||
for _, s := range l[1:] {
|
||||
switch {
|
||||
case s < min:
|
||||
min = s
|
||||
case s > max:
|
||||
max = s
|
||||
xfix := strs[0]
|
||||
// short-circuit single-element list
|
||||
if len(strs) == 1 {
|
||||
return xfix
|
||||
}
|
||||
// compare first to rest
|
||||
for _, str := range strs[1:] {
|
||||
xfixl := len(xfix)
|
||||
strl := len(str)
|
||||
// short-circuit empty strings
|
||||
if xfixl == 0 || strl == 0 {
|
||||
return ""
|
||||
}
|
||||
// maximum possible length
|
||||
maxl := xfixl
|
||||
if strl < maxl {
|
||||
maxl = strl
|
||||
}
|
||||
// compare letters
|
||||
if pre {
|
||||
// prefix, iterate left to right
|
||||
for i := 0; i < maxl; i++ {
|
||||
if xfix[i] != str[i] {
|
||||
xfix = xfix[:i]
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// suffix, iterate right to left
|
||||
for i := 0; i < maxl; i++ {
|
||||
xi := xfixl - i - 1
|
||||
si := strl - i - 1
|
||||
if xfix[xi] != str[si] {
|
||||
xfix = xfix[xi+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(min) && i < len(max); i++ {
|
||||
if min[i] != max[i] {
|
||||
return min[:i]
|
||||
}
|
||||
}
|
||||
// In the case where lengths are not equal but all bytes
|
||||
// are equal, min is the answer ("foo" < "foobar").
|
||||
return min
|
||||
return xfix
|
||||
}
|
||||
|
||||
// Returns the mode in which MinIO is running
|
||||
|
||||
Reference in New Issue
Block a user