From 36945bad07097c9c2dd89dc51ca46a6cfa76550c Mon Sep 17 00:00:00 2001 From: andig Date: Mon, 27 Nov 2023 13:08:52 +0500 Subject: [PATCH] chore: guard switch against duplicate cases --- provider/switch.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/provider/switch.go b/provider/switch.go index 2d736f2a54..3b7f5fc710 100644 --- a/provider/switch.go +++ b/provider/switch.go @@ -32,6 +32,14 @@ func NewSwitchFromConfig(other map[string]interface{}) (Provider, error) { return nil, err } + cases := make(map[string]struct{}) + for _, c := range cc.Switch { + if _, ok := cases[c.Case]; ok { + return nil, fmt.Errorf("switch: duplicate case: %s", c.Case) + } + cases[c.Case] = struct{}{} + } + o := &switchProvider{ cases: cc.Switch, dflt: cc.Default,