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

Hash with Files is manipulated when using deep_locate #450

Open
magynhard opened this issue Jun 13, 2018 · 1 comment
Open

Hash with Files is manipulated when using deep_locate #450

magynhard opened this issue Jun 13, 2018 · 1 comment
Labels
bug? hacktoberfest Issues that would be suitable for Hacktoberfest

Comments

@magynhard
Copy link

magynhard commented Jun 13, 2018

When I'm using deep_locate on a Hash that includes a file, it is manipulated.

I figured out this problem, when checking if a file is included in a hash, before sending it via POST to a REST service. The file isn't sent anymore, when calling deep_locate before.

If you comment the line with deep_locate, everything is fine.

def hash_include_file?(hash)
  lambda_condition = lambda { |key, value, object| value.is_a? File }
  Hashie::Extensions::DeepLocate.deep_locate(lambda_condition, hash) != []
end

file = File.new('example_file.txt','rb')
params = { file: file }

RestClient.post "www.example.com", params, {content_type: 'multipart/form-data'}

hash_include_file? params # this line makes the difference!

RestClient.post "www.example.com", params, {content_type: 'multipart/form-data'}

The requests differ in this way (see the Content-Length):

RestClient.post "http://www.example.com", 14904 byte(s) length, 
"Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", 
"Content-Length"=>"14904", 
"Content-Type"=>"multipart/form-data; boundary=----RubyFormBoundary9IgAHjSw4d2O3mJg"
, 
"User-Agent"=>"rest-client/2.0.2 (mingw32 x86_64) ruby/2.4.4p296"
# => 200 OK |  0 bytes
RestClient.post "http://www.example.com", "------RubyFormBoundaryK6UWn0DJxwKAgVsG\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example_file.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n------RubyFormBoundaryK6UWn
0DJxwKAgVsG--\r\n", 
"Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", 
"Content-Length"=>"186", 
"Content-Type"=>"multipart/form-data; boundary=----RubyFormBoundaryK6UWn0DJxwKAgVsG", 
"User-Agent"=>"rest-client/2.0.2 (mingw32 x8
6_64) ruby/2.4.4p296"
# => 200 OK |  0 bytes

I created a example project, including a rspec file, to show the problem.
https://github.com/entwanderer/rest-client-hashie

@magynhard
Copy link
Author

Since after almost a year still no reaction has taken place, I have cleaned up the example project. The above example should be sufficient if the bug is fixed at some point.

@dblock dblock added the bug? label Jun 11, 2020
@michaelherold michaelherold added the hacktoberfest Issues that would be suitable for Hacktoberfest label Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug? hacktoberfest Issues that would be suitable for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

3 participants