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

If parameter has symbol, it will be error #219

Closed
lion-man44 opened this issue Apr 18, 2024 · 6 comments · Fixed by #221
Closed

If parameter has symbol, it will be error #219

lion-man44 opened this issue Apr 18, 2024 · 6 comments · Fixed by #221
Labels
bug Something isn't working

Comments

@lion-man44
Copy link

lion-man44 commented Apr 18, 2024

I just update this gem v0.18.0 and got error like this.

     Failure/Error: Integer(string || '')

     TypeError:
       can't convert Symbol into Integer

I found problem here.
This code can't get Symbol.

  def number_or_nil(string)
    Integer(string || '')
  rescue ArgumentError
    nil
  end

if you use json in router or something, probably it includes Symbol in value this code.

    parameters.each_pair do |key, value|
      next unless number_or_nil(value)

This is my parameters.

{:format=>:json, :controller=>"*", :action=>"create", :id=>"897"}

So, could anyone help to submit PR like this?

      next unless number_or_nil(value.to_s)

I tried to create PR but I couldn't understand how to write test code in this gem.

@exoego
Copy link
Owner

exoego commented Apr 18, 2024

Could you make a repro, something like this:
https://github.com/rhiroe/try-rspec-openapi

@lion-man44
Copy link
Author

lion-man44 commented Apr 18, 2024

Sorry, it will take times in my environment if you are okay just try this one in your router.

Rails.application.routes.draw do
  defaults format: :json do
  end
end

And then, I found workaround thankfully if I rewrite :json to 'json' as a String.
It worked

Rails.application.routes.draw do
  defaults format: 'json' do
  end
end

@johnphamvan
Copy link

Thanks for the workaround @lion-man44.

A bit more info for @exoego, while running the gem locally with a bit of debug code:

    76:   def number_or_nil(string)
    77:     if string.is_a?(String)
    78:       Integer(string || '')
    79:     else
 => 80:       binding.irb
    81:     end
    82:   rescue ArgumentError
    83:     nil
    84:   end
    85: end

irb(#<Object:0x000000013c835990>):001> string
=> :json

@exoego
Copy link
Owner

exoego commented Apr 20, 2024

@lion-man44 @johnphamvan
Thanks for reporting. This was fixed and released in v0.18.1

@johnphamvan
Copy link

Thanks for maintaining this project @exoego!

@lion-man44
Copy link
Author

Thanks for fixing this @exoego
And Thanks for helping me @johnphamvan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants