Plugins: filter nan values (#20137)
This commit is contained in:
parent
0ea32cc82a
commit
aeb3aba168
2 changed files with 12 additions and 3 deletions
|
|
@ -1,8 +1,6 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
|
|
@ -30,7 +28,7 @@ func (p *getter) FloatGetter() (func() (float64, error), error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
f, err := strconv.ParseFloat(s, 64)
|
||||
f, err := parseFloat(s)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package plugin
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
|
|
@ -42,3 +44,12 @@ func contextLogger(ctx context.Context, log *util.Logger) *util.Logger {
|
|||
|
||||
return log
|
||||
}
|
||||
|
||||
// parseFloat rejects NaN and Inf values
|
||||
func parseFloat(payload string) (float64, error) {
|
||||
f, err := strconv.ParseFloat(payload, 64)
|
||||
if err == nil && (math.IsNaN(f) || math.IsInf(f, 0)) {
|
||||
return 0, fmt.Errorf("invalid float value: %s", payload)
|
||||
}
|
||||
return f, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue