From a6b7585eae06ebb7f4f63db774d871ef9a012744 Mon Sep 17 00:00:00 2001 From: Shirong Lu <73147033+happysnaker@users.noreply.github.com> Date: Fri, 3 Jul 2026 17:47:21 +0800 Subject: [PATCH] fix: allow empty string to reset StringToString flag Currently, passing an empty string to a StringToString flag returns an error. This makes it impossible to override a non-empty default map with an empty one. This change allows an empty string value to reset the flag to an empty map. Fixes #312 --- string_to_string.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/string_to_string.go b/string_to_string.go index 518e1366..c2c6eef2 100644 --- a/string_to_string.go +++ b/string_to_string.go @@ -24,6 +24,14 @@ func newStringToStringValue(val map[string]string, p *map[string]string) *string // Set updates the flag value from the given string, adding additional mappings or updating existing ones. func (s *stringToStringValue) Set(val string) error { var ss []string + // Allow empty string to reset the map to empty + if val == "" { + for k := range *s.value { + delete(*s.value, k) + } + s.changed = true + return nil + } n := strings.Count(val, "=") switch n { case 0: