Plugins: filter nan values (#20137)

This commit is contained in:
andig 2025-03-26 17:44:49 +01:00 • committed by GitHub
parent 0ea32cc82a
commit aeb3aba168
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View file

@ -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
}