mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Merge pull request #15270 from stonezdj/21jun05_fix_rest_int_parse_fail
Fix invalid syntax errors when int value is convert to scientific notation
This commit is contained in:
commit
7b84f4e137
@ -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