Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueWithShadows returning a non empty array when there are no values #310

Closed
NDagestad opened this issue Dec 5, 2021 · 0 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@NDagestad
Copy link
Contributor

NDagestad commented Dec 5, 2021

When getting the values and shadows of a key, if there are no values at all, StringsWithShadows will return an array with an empty string. This does not seem like the right behaviour.
I would expect StringsWithShadows to return an empty array if there are no values. The documentation says that ValueWithShadows returns the raw value so there is a case to be made for it to return an empty string, but I would argue it is more intuitive to return an empty array even there.

Something like this should be enough to fix it from what I can tell (it is good enough in my case at least)

diff --git a/key.go b/key.go
index 0302c29..2147974 100644
--- a/key.go
+++ b/key.go
@@ -113,6 +113,9 @@ func (k *Key) Value() string {
 // ValueWithShadows returns raw values of key and its shadows if any.
 func (k *Key) ValueWithShadows() []string {
        if len(k.shadows) == 0 {
+               if k.value == "" {
+                       return []string{}
+               }
                return []string{k.value}
        }
        vals := make([]string, len(k.shadows)+1)
@unknwon unknwon added bug Something isn't working good first issue Good for newcomers labels Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants