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

Please don't extend Ruby core objects #4

Open
d4rky-pl opened this issue Dec 11, 2015 · 5 comments
Open

Please don't extend Ruby core objects #4

d4rky-pl opened this issue Dec 11, 2015 · 5 comments

Comments

@d4rky-pl
Copy link

I've just spent 5 hours trying to debug why my application suddenly started crashing for no apparent reason until I found out this gem is extending Array with to_hash method. Please don't do this - this can cause serious issues when code expects hash or hash-like object but also supports arrays, especially considering this was not expected from a gem for external API integration.

@adrianpacala
Copy link

👍

1 similar comment
@mklocek
Copy link

mklocek commented Dec 11, 2015

👍

@kingcons
Copy link

kingcons commented Apr 6, 2016

To give a specific example, I added this gem to a Rails project and simply having it in the Gemfile caused any requests containing a file encoded with multipart/form-data to throw an exception during Rack parsing, long before the controller action had any chance to fire.

[2016-04-06 12:06:55] ERROR ArgumentError: unexpected prefix: {"RackMultipart"=>nil, ".jpg"=>nil}
    /Users/brit/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tmpdir.rb:111:in `make_tmpname'
    /Users/brit/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tmpdir.rb:129:in `create'
    /Users/brit/.rbenv/versions/2.3.0/lib/ruby/2.3.0/tempfile.rb:131:in `initialize'
    /Users/brit/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/multipart/parser.rb:22:in `new'
    /Users/brit/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/multipart/parser.rb:22:in `block in create'
    /Users/brit/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/multipart/parser.rb:135:in `get_current_head_and_filename_and_content_type_and_name_and_body'

This can be tested as easily as rails new whatever, adding imgurapi to the Gemfile, and running curl -iv -F filename=test.jpg -F [email protected] http://localhost:3000/an-example with a local file of your choosing. Since the request is parsed before routing, you don't even need to define a route to observe this failure. It is my expectation that the to_hash extension to Arrays is the culprit.

@tamvm
Copy link

tamvm commented Jun 28, 2016

👍 , they're not "nice extensions to base classes", I forked a version without these extensions: https://github.com/tam-vo/imgur

@InvaQ
Copy link

InvaQ commented Jun 29, 2016

I have the same problem, but i didn't include gem 'imgurapi'. im using ruby 2.3.1 rails 4.2.6. So, how exactly i have to solve this issue? Btw, im newbie in rails.

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

No branches or pull requests

6 participants