mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
Fix invalid syntax errors when int value is convert to scientific notation
Add parseInt function to parse the scientific notation Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
parent
4e1f6633af
commit
41968091a2
@ -90,12 +90,12 @@ type IntType struct {
|
||||
}
|
||||
|
||||
func (t *IntType) validate(str string) error {
|
||||
_, err := strconv.Atoi(str)
|
||||
_, err := parseInt(str)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *IntType) get(str string) (interface{}, error) {
|
||||
return strconv.Atoi(str)
|
||||
return parseInt(str)
|
||||
}
|
||||
|
||||
// PortType ...
|
||||
@ -237,3 +237,17 @@ func parseInt64(str string) (int64, error) {
|
||||
|
||||
return 0, fmt.Errorf("invalid int64 string: %s", str)
|
||||
}
|
||||
|
||||
func parseInt(str string) (int, error) {
|
||||
val, err := strconv.ParseInt(str, 10, 32)
|
||||
if err == nil {
|
||||
return int(val), nil
|
||||
}
|
||||
|
||||
fval, err := strconv.ParseFloat(str, 32)
|
||||
if err == nil && fval == math.Trunc(fval) {
|
||||
return int(fval), nil
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("invalid int string: %s", str)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user