mirror of
https://github.com/minio/minio.git
synced 2025-07-08 16:42:17 -04:00
Fix bug with fields that contain trimming spaces (#10079)
String x might contain trimming spaces. And it needs to be trimmed. For example, in csv files, there might be trimming spaces in a field that ought to meet a query condition that contains the value without trimming spaces. This applies to both intCast and floatCast functions.
This commit is contained in:
parent
eb6bf454f1
commit
e464a5bfbc
@ -465,7 +465,9 @@ func intCast(v *Value) (int64, error) {
|
|||||||
case string:
|
case string:
|
||||||
// Parse as number, truncate floating point if
|
// Parse as number, truncate floating point if
|
||||||
// needed.
|
// needed.
|
||||||
res, ok := strToInt(x)
|
// String might contain trimming spaces, which
|
||||||
|
// needs to be trimmed.
|
||||||
|
res, ok := strToInt(strings.TrimSpace(x))
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errCastFailure("could not parse as int")
|
return 0, errCastFailure("could not parse as int")
|
||||||
}
|
}
|
||||||
@ -473,7 +475,9 @@ func intCast(v *Value) (int64, error) {
|
|||||||
case []byte:
|
case []byte:
|
||||||
// Parse as number, truncate floating point if
|
// Parse as number, truncate floating point if
|
||||||
// needed.
|
// needed.
|
||||||
res, ok := strToInt(string(x))
|
// String might contain trimming spaces, which
|
||||||
|
// needs to be trimmed.
|
||||||
|
res, ok := strToInt(strings.TrimSpace(string(x)))
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, errCastFailure("could not parse as int")
|
return 0, errCastFailure("could not parse as int")
|
||||||
}
|
}
|
||||||
@ -491,13 +495,13 @@ func floatCast(v *Value) (float64, error) {
|
|||||||
case int:
|
case int:
|
||||||
return float64(x), nil
|
return float64(x), nil
|
||||||
case string:
|
case string:
|
||||||
f, err := strconv.ParseFloat(x, 64)
|
f, err := strconv.ParseFloat(strings.TrimSpace(x), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errCastFailure("could not parse as float")
|
return 0, errCastFailure("could not parse as float")
|
||||||
}
|
}
|
||||||
return f, nil
|
return f, nil
|
||||||
case []byte:
|
case []byte:
|
||||||
f, err := strconv.ParseFloat(string(x), 64)
|
f, err := strconv.ParseFloat(strings.TrimSpace(string(x)), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errCastFailure("could not parse as float")
|
return 0, errCastFailure("could not parse as float")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user