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

Accessing array slices fails for non-lowercase keys #1386

Closed
3 tasks done
awrichar opened this issue Jun 23, 2022 · 2 comments · Fixed by #1387
Closed
3 tasks done

Accessing array slices fails for non-lowercase keys #1386

awrichar opened this issue Jun 23, 2022 · 2 comments · Fixed by #1387
Labels
kind/bug Something isn't working

Comments

@awrichar
Copy link

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.
  • I have checked the troubleshooting guide for my problem, without success.

Viper Version

master

Go Version

1.17.9

Config Source

Files

Format

YAML

Repl.it link

No response

Code reproducing the issue

diff --git a/viper_test.go b/viper_test.go
index c41a1e7..536a53d 100644
--- a/viper_test.go
+++ b/viper_test.go
@@ -2517,6 +2517,7 @@ func TestKeyDelimiter(t *testing.T) {
 
 var yamlDeepNestedSlices = []byte(`TV:
 - title: "The expanse"
+  originalNetwork: "syfy"
   seasons:
   - first_released: "December 14, 2015"
     episodes:
@@ -2547,6 +2548,7 @@ func TestSliceIndexAccess(t *testing.T) {
        require.NoError(t, err)
 
        assert.Equal(t, "The expanse", v.GetString("tv.0.title"))
+       assert.Equal(t, "syfy", v.GetString("tv.0.originalNetwork"))
        assert.Equal(t, "February 1, 2017", v.GetString("tv.0.seasons.1.first_released"))
        assert.Equal(t, "Static", v.GetString("tv.0.seasons.1.episodes.2.title"))
        assert.Equal(t, "December 15, 2015", v.GetString("tv.0.seasons.0.episodes.1.air_date"))

Expected Behavior

If my config contains an array, and one of the sub-keys in that array is non-lowercase (ie contains one or more capital letters), Viper is unable to retrieve the key using slice notation.

I modified a simple unit test to contain this array element:

- title: "The expanse"
  originalNetwork: "syfy"

When accessing the value with v.GetString("tv.0.originalNetwork"), I expect to receive the value "syfy".

Actual Behavior

An empty string is returned.

Steps To Reproduce

No response

Additional Information

No response

@awrichar awrichar added the kind/bug Something isn't working label Jun 23, 2022
@github-actions
Copy link

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

@awrichar
Copy link
Author

For the record: it looks like this support was originally added in #861, so it's possible something was missed there.

awrichar added a commit to kaleido-io/firefly that referenced this issue Jun 23, 2022
Due to spf13/viper#1386, array keys with mixed
case are not parsed correctly. At least for the time being, mitigate
by changing some keys to all lowercase.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
awrichar added a commit to awrichar/viper that referenced this issue Jun 23, 2022
Fixes spf13#1386

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
awrichar added a commit to kaleido-io/firefly that referenced this issue Jun 24, 2022
Due to spf13/viper#1386, array keys with mixed
case are not parsed correctly. At least for the time being, mitigate
by changing some keys to all lowercase.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
awrichar added a commit to kaleido-io/firefly that referenced this issue Jun 28, 2022
Due to spf13/viper#1386, array keys with mixed
case are not parsed correctly. At least for the time being, mitigate
by changing some keys to all lowercase.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
awrichar added a commit to awrichar/viper that referenced this issue Jul 11, 2022
Fixes spf13#1386

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
sagikazarmark pushed a commit that referenced this issue Jul 12, 2022
Fixes #1386

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant