Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit ffff8cf

Browse files
author
Tobias Haagen Michaelsen
committed
Be aware when using Hash or Array as default value for unknown Hash keys.
If you're using `Hash.new([])` or `Hash#default=` then it's the same object that is assigned to each unknown key, so you'll be adding to the same array when e.g. adding multiple AX attributes.
1 parent 41d8323 commit ffff8cf

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

lib/openid/extensions/ax.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ class KeyValueMessage < AXMessage
275275
def initialize
276276
super()
277277
@mode = nil
278-
@data = {}
279-
@data.default = []
278+
@data = Hash.new { |hash, key| hash[key] = [] }
280279
end
281280

282281
# Add a single value for the given attribute type to the

lib/openid/store/memory.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ module Store
99
class Memory < Interface
1010

1111
def initialize
12-
@associations = {}
13-
@associations.default = {}
12+
@associations = Hash.new { |hash, key| hash[key] = {} }
1413
@nonces = {}
1514
end
1615

0 commit comments

Comments
 (0)