From 67ec0ee0c977788d2300656f44f62aac3353a947 Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Sun, 30 Jul 2023 10:51:23 +0000 Subject: [PATCH] fix(kconfig): Correctly handle integer conversions from map interface When the `NewKeyValueMapFromMap` was used with integers, this would result in a Golang value of `(int=5)%s` for example. Correctly handle by doing a type check. Signed-off-by: Alexander Jung --- kconfig/config.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kconfig/config.go b/kconfig/config.go index a866096ce..e12505394 100644 --- a/kconfig/config.go +++ b/kconfig/config.go @@ -24,7 +24,13 @@ func NewKeyValueMapFromSlice(values ...interface{}) KeyValueMap { mapping := KeyValueMap{} for _, value := range values { - str := fmt.Sprintf("%s", value) + var str string + switch t := value.(type) { + case string: + str = t + case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: + str = fmt.Sprintf("%d", t) + } tokens := strings.SplitN(str, "=", 2) if len(tokens) > 1 { mapping[tokens[0]] = &KeyValue{ @@ -57,6 +63,8 @@ func NewKeyValueMapFromMap(values map[string]interface{}) KeyValueMap { v = "y" } mapping[key].Value = v + case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: + mapping[key].Value = fmt.Sprintf("%d", casting) default: mapping[key].Value = fmt.Sprintf("%s", casting) }