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

Slices are cleared and appended, should be overwritten #27

Closed
pavelbazika opened this issue Nov 30, 2020 · 3 comments
Closed

Slices are cleared and appended, should be overwritten #27

pavelbazika opened this issue Nov 30, 2020 · 3 comments

Comments

@pavelbazika
Copy link

Hi

I've a scenario, where at first configuration struct is loaded from config file and then envconfig is applied to overwrite some settings from environment variables, when they exist.

One of the fields in the config struct is a slice of string. When an environment variable for this slice exists, the slice is not replaced by value from the environment variable. Instead, resulting slice contains as many items as it was in config file set to empty string followed by environment variable value.

For example:

  • original slice value from config file - ["foo"]
  • environment variable value - "bar"
  • slice after envconfig - ["", "bar"]

I guess the bug is in function setSliceField on line

slice := reflect.MakeSlice(value.Type(), value.Len(), value.Cap())

There shouldn't be value.Len() but 0 in my opinion.

Best Regards

Pavel

@vrischmann
Copy link
Owner

Hi,

can you make a small test case which reproduces the problem ?

Also since you seem to have an idea of where the problem is I'd be happy to review and merge a PR.

@pavelbazika
Copy link
Author

Ok, will do.

@pavelbazika
Copy link
Author

#28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants