Skip to content

Commit

Permalink
Fix EncryptedConfiguration not behaving like Hash
Browse files Browse the repository at this point in the history
Previously, `EncryptedConfiguration` was [updated][1] to use
`InheritableOptions` so that keys could be called like methods. It was
later [updated again][2] to ensure that it behaved both like a `Hash` and
`OrderedOptions`. In this second change, the `InheritableOptions`
instance was accidentally nested with another `InheritableOptions`
instance.

This continued to mostly work as expected because `InheritableOptions`
will fall back to the inner `InheritableOptions` when the outer one
doesn't have a key. However, any methods that try to treat the outer
`InheritableOptions` like it should know about all of its keys will fail
(for example, `#keys`, `#to_h`, `#to_json`, etc.)

This commit fixes the issue by removing the extraneous outer
`InheritableOptions` instance.

[1]: a6a9fed
[2]: 80585da
  • Loading branch information
skipkayhil committed Jun 22, 2023
1 parent 7a033f5 commit 8355658
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,3 +1,8 @@
* Fix `EncryptedConfiguration` returning incorrect values for some `Hash`
methods

*Hartley McGuire*

* Don't show secrets for `MessageEncryptor#inspect`.

Before:
Expand Down
Expand Up @@ -92,7 +92,7 @@ def deep_transform(hash)
end

def options
@options ||= ActiveSupport::InheritableOptions.new(deep_transform(config))
@options ||= deep_transform(config)
end

def deserialize(content)
Expand Down
1 change: 1 addition & 0 deletions activesupport/test/encrypted_configuration_test.rb
Expand Up @@ -45,6 +45,7 @@ class EncryptedConfigurationTest < ActiveSupport::TestCase
assert_not @credentials.something.bad
assert_equal "bar", @credentials.dig(:something, :nested, :foo)
assert_equal "bar", @credentials.something.nested.foo
assert_equal [:something], @credentials.keys
assert_equal [:good, :bad, :nested], @credentials.something.keys
assert_equal ({ good: true, bad: false, nested: { foo: "bar" } }), @credentials.something
end
Expand Down

0 comments on commit 8355658

Please sign in to comment.