Skip to content

Commit

Permalink
Merge pull request #1844 from Nyangawa/fix-file-validator
Browse files Browse the repository at this point in the history
fix: enforce tempfile to be a Tempfile object
  • Loading branch information
dblock committed Dec 14, 2018
2 parents 766cdb5 + d307fa1 commit b368380
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 b368380

Please sign in to comment.