Skip to content

Commit

Permalink
fix: enforce tempfile to be a Tempfile object
Browse files Browse the repository at this point in the history
  • Loading branch information
asakawa committed Dec 13, 2018
1 parent 766cdb5 commit d307fa1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Your contribution here.
* [#1833](https://github.com/ruby-grape/grape/pull/1833): Allows to set the `ParamBuilder` globally - [@myxoh](https://github.com/myxoh).
* [#1844](https://github.com/ruby-grape/grape/pull/1844): Fix: enforce `:tempfile` to be a `Tempfile` object in `File` validator - [@Nyangawa](https://github.com/Nyangawa).

#### Fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/types/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def value_coerced?(value)
# Rack::Request creates a Hash with filename,
# content type and an IO object. Do a bit of basic
# duck-typing.
value.is_a?(::Hash) && value.key?(:tempfile)
value.is_a?(::Hash) && value.key?(:tempfile) && value[:tempfile].is_a?(Tempfile)
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/grape/validations/validators/coerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ def self.parsed?(value)
post '/upload', file: 'not a file'
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('file is invalid')

post '/upload', file: { filename: 'fake file', tempfile: '/etc/passwd' }
expect(last_response.status).to eq(400)
expect(last_response.body).to eq('file is invalid')
end

it 'Nests integers' do
Expand Down

0 comments on commit d307fa1

Please sign in to comment.