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

reinstating symbolize keys in the to_hash method. #85

Merged
merged 1 commit into from Feb 26, 2013

Conversation

cromulus
Copy link

this adds the symbolize keys option back to the to_hash method. Removing this broke a few gems, namely, the omniauth-oauth2 gem, upon which, many omniauth strategies rely.

mbleigh added a commit that referenced this pull request Feb 26, 2013
reinstating symbolize keys in the to_hash method.
@mbleigh mbleigh merged commit 67c0bc6 into hashie:master Feb 26, 2013
@cromulus
Copy link
Author

wow. fast! Thanks!

@jch
Copy link
Contributor

jch commented Feb 26, 2013

🤘 nice!

@saimonmoore
Copy link

👍

@saimonmoore
Copy link

this broke facebook auth for us

@jch
Copy link
Contributor

jch commented Feb 27, 2013

2.0.2 has been released with this fix ;)

@mhuggins
Copy link
Contributor

I'm running into an issue with this code. I'm trying to take a basic hash with string keys and convert it to a basic hash with symbol keys. Take the following example.

hash = {"id": 1, "name": "Bob"}
hash = Hashie::Hash[hash].to_hash(symbolize_keys: true)

This throws an exception in Hashie's to_hash method using the code provided here. The reason is that on line 15 the value of k is being changed from "id" or "name" to :id or :name respectively. Then on line 17, the call to self[k] returns nil since hash[:id] is not defined (only hash["id"] is defined), which then errors when trying to evaluate nil.each.

I think a proper fix would be to assign the key to a NEW variable instead. e.g.:

assignment_key = options[:symbolize_keys] ? k.to_sym : k.to_s
out[assignment_key] ||= []
self[k].each do |array_object|
  out[assignment_key] << (Hash === array_object ? array_object.to_hash : array_object)
end

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

Successfully merging this pull request may close these issues.

None yet

5 participants