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

Fix behavior of trying to parse non-string objects #499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YuheiNakasaka
Copy link

@YuheiNakasaka YuheiNakasaka commented Jun 3, 2022

Some Object may return true for respond_to?(:to_str) but actually return nil instead of String when to_str is called.

A good example is the Rails encrypted credentials in Rails 7.0, an object called InheritableOptions that extends Hash.
InheritableOptions implements method_missing and returns true for respond_to?(:to_str) but nil when actually calling to_str.
https://github.com/rails/rails/blob/7-0-stable/activesupport/lib/active_support/ordered_options.rb#L43

Therefore, the following implementation will cause an error.

h = ActiveSupport::InheritableOptions.new({ a: 1, b: 2 })
h.is_a? Hash #=> true
JSON(h) #=> TypeError: no implicit conversion of nil into String

This PR implements strict checking of arguments to avoid this kind of error.

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

1 participant