mirror of
https://github.com/minio/minio.git
synced 2025-11-11 06:20:14 -05:00
committed by
Nitish Tiwari
parent
52b159b1db
commit
bebaff269c
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
var (
|
||||
// Regex to extract ellipses syntax inputs.
|
||||
regexpEllipses = regexp.MustCompile(`(.*)({[0-9]*\.\.\.[0-9]*})(.*)`)
|
||||
regexpEllipses = regexp.MustCompile(`(.*)({[0-9a-z]*\.\.\.[0-9a-z]*})(.*)`)
|
||||
|
||||
// Ellipses constants
|
||||
openBraces = "{"
|
||||
@@ -53,13 +53,24 @@ func parseEllipsesRange(pattern string) (seq []string, err error) {
|
||||
return nil, errors.New("Invalid argument")
|
||||
}
|
||||
|
||||
var hexadecimal bool
|
||||
var start, end uint64
|
||||
if start, err = strconv.ParseUint(ellipsesRange[0], 10, 64); err != nil {
|
||||
return nil, err
|
||||
// Look for hexadecimal conversions if any.
|
||||
start, err = strconv.ParseUint(ellipsesRange[0], 16, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hexadecimal = true
|
||||
}
|
||||
|
||||
if end, err = strconv.ParseUint(ellipsesRange[1], 10, 64); err != nil {
|
||||
return nil, err
|
||||
// Look for hexadecimal conversions if any.
|
||||
end, err = strconv.ParseUint(ellipsesRange[1], 16, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hexadecimal = true
|
||||
}
|
||||
|
||||
if start > end {
|
||||
@@ -68,9 +79,17 @@ func parseEllipsesRange(pattern string) (seq []string, err error) {
|
||||
|
||||
for i := start; i <= end; i++ {
|
||||
if strings.HasPrefix(ellipsesRange[0], "0") && len(ellipsesRange[0]) > 1 || strings.HasPrefix(ellipsesRange[1], "0") {
|
||||
seq = append(seq, fmt.Sprintf(fmt.Sprintf("%%0%dd", len(ellipsesRange[1])), i))
|
||||
if hexadecimal {
|
||||
seq = append(seq, fmt.Sprintf(fmt.Sprintf("%%0%dx", len(ellipsesRange[1])), i))
|
||||
} else {
|
||||
seq = append(seq, fmt.Sprintf(fmt.Sprintf("%%0%dd", len(ellipsesRange[1])), i))
|
||||
}
|
||||
} else {
|
||||
seq = append(seq, fmt.Sprintf("%d", i))
|
||||
if hexadecimal {
|
||||
seq = append(seq, fmt.Sprintf("%x", i))
|
||||
} else {
|
||||
seq = append(seq, fmt.Sprintf("%d", i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,7 @@ func TestHasEllipses(t *testing.T) {
|
||||
true,
|
||||
},
|
||||
{
|
||||
|
||||
[]string{
|
||||
"mydisk-{1...4}{1..2.}",
|
||||
},
|
||||
@@ -201,6 +202,11 @@ func TestFindEllipsesPatterns(t *testing.T) {
|
||||
false,
|
||||
0,
|
||||
},
|
||||
{
|
||||
"{f...z}",
|
||||
false,
|
||||
0,
|
||||
},
|
||||
// Test for valid input.
|
||||
{
|
||||
"{1...64}",
|
||||
@@ -222,6 +228,11 @@ func TestFindEllipsesPatterns(t *testing.T) {
|
||||
true,
|
||||
36,
|
||||
},
|
||||
{
|
||||
"{1...a}",
|
||||
true,
|
||||
10,
|
||||
},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
|
||||
@@ -44,7 +44,7 @@ func (host Host) String() string {
|
||||
return host.Name
|
||||
}
|
||||
|
||||
return host.Name + ":" + host.Port.String()
|
||||
return net.JoinHostPort(host.Name, host.Port.String())
|
||||
}
|
||||
|
||||
// Equal - checks whether given host is equal or not.
|
||||
@@ -129,6 +129,10 @@ func ParseHost(s string) (*Host, error) {
|
||||
isPortSet = true
|
||||
}
|
||||
|
||||
if i := strings.Index(host, "%"); i > -1 {
|
||||
host = host[:i]
|
||||
}
|
||||
|
||||
if !isValidHost(host) {
|
||||
return nil, errors.New("invalid hostname")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user