From 5801e8ff4fdb88068ace9a24443055b8eaab76e1 Mon Sep 17 00:00:00 2001 From: Aditya030207 <230317630+Aditya030207@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:30:44 +0530 Subject: [PATCH] fix: Reject NaN flag weights --- internal/cmd/cmd_test.go | 1 + internal/cmd/flag_update.go | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/cmd/cmd_test.go b/internal/cmd/cmd_test.go index 1777c36..6040573 100644 --- a/internal/cmd/cmd_test.go +++ b/internal/cmd/cmd_test.go @@ -4966,6 +4966,7 @@ func TestFlagUpdateWeight(t *testing.T) { {"over 100 in total", "hero=40", ""}, // filled in below {"not a pair", "hero", "is not ="}, {"not a percentage", "hero=lots", "is not a percentage"}, + {"not a number", "hero=NaN", "is not a percentage"}, {"over 100 on its own", "hero=140", "is not a percentage"}, {"negative", "hero=-1", "is not a percentage"}, {"the same variant twice", "hero=10,hero=20", "given twice"}, diff --git a/internal/cmd/flag_update.go b/internal/cmd/flag_update.go index 4d20258..edabb5b 100644 --- a/internal/cmd/flag_update.go +++ b/internal/cmd/flag_update.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "math" "strconv" "strings" @@ -104,7 +105,7 @@ func parseWeights(args []string) ([]weightRef, error) { return nil, usageErrorf("--weight %q is not =", pair) } weight, err := strconv.ParseFloat(raw, 64) - if err != nil || weight < 0 || weight > 100 { + if err != nil || math.IsNaN(weight) || weight < 0 || weight > 100 { return nil, usageErrorf("--weight %s: %q is not a percentage between 0 and 100", ref, raw) } if ref == controlVariantKey {