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

#to_hash should not replace nested config objects with Hash #160

Merged
merged 1 commit into from
Dec 19, 2016

Conversation

seikichi
Copy link
Contributor

Config::Options#to_hash mistakenly replaces nested Config::Options
objects in arrays with Hash objects. Consider the following code:

> config = Config.load_files("spec/fixtures/development.yml");
> config.section.servers[0].class
Config::Options
> config.to_hash
{:size=>2, :section=>{:size=>3, :servers=>[{:name=>"yahoo.com"}, {:name=>"amazon.com"}]}}
> config.section.servers[0].class
Hash

Therefore, after evaluating config.to_hash,
config.sections.servers[0].name raises an exception.
This is because Config::Options#descend_array overwrites array elements.

This commit fixes the above problem by modifying the
Config::Options#descend_array.

`Config::Options#to_hash` mistakenly replaces nested `Config::Options`
objects in arrays with `Hash` objects. Consider the following code:

```ruby
> config = Config.load_files("spec/fixtures/development.yml");
> config.section.servers[0].class
Config::Options
> config.to_hash
{:size=>2, :section=>{:size=>3, :servers=>[{:name=>"yahoo.com"}, {:name=>"amazon.com"}]}}
> config.section.servers[0].class
Hash
```

Therefore, after evaluating `config.to_hash`,
`config.sections.servers[0].name` raises an exception.
This is because `Config::Options#descend_array` overwrites array elements.

This commit fixes the above problem by modifying the
`Config::Options#descend_array`.
@pkuczynski pkuczynski changed the title Fix that #to_hash replaces nested config objects with Hash #to_hash should not replace nested config objects with Hash Dec 19, 2016
@pkuczynski pkuczynski merged commit 4a0efa5 into rubyconfig:master Dec 19, 2016
@pkuczynski
Copy link
Member

Awesome, thanks!

@pkuczynski pkuczynski added this to the 1.3.1 milestone Dec 19, 2016
@pkuczynski pkuczynski added the bug label Dec 19, 2016
@pkuczynski pkuczynski modified the milestones: 1.3.1, 1.4 Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants