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

Force name to be string when looking up mime type #4545

Merged
merged 3 commits into from
Jun 4, 2019

Conversation

lildude
Copy link
Member

@lildude lildude commented Jun 3, 2019

Description

#4531 switched a dependency from using mime-types to mini_mime but missed a scenario that didn't come up until I started testing the forth-coming v.7.5.0 release: _mime_type() will fail if nil is passed as the filename, as is the case when GitHub serves raw data.

This results in MiniMime.lookup_by_filename(name) failing with:

TypeError: no implicit conversion of nil into String
    /var/lib/jenkins/workspace/github/vendor/gems/2.6.2/ruby/2.6.0/gems/mini_mime-1.0.1/lib/mini_mime.rb:45:in `extname'
    /var/lib/jenkins/workspace/github/vendor/gems/2.6.2/ruby/2.6.0/gems/mini_mime-1.0.1/lib/mini_mime.rb:45:in `lookup_by_filename'
    /var/lib/jenkins/workspace/github/vendor/gems/2.6.2/ruby/2.6.0/gems/mini_mime-1.0.1/lib/mini_mime.rb:6:in `lookup_by_filename'
    /var/lib/jenkins/workspace/github/vendor/gems/2.6.2/ruby/2.6.0/gems/github-linguist-7.4.0.32.g7f67bc95/lib/linguist/blob_helper.rb:36:in `_mime_type'
    /var/lib/jenkins/workspace/github/vendor/gems/2.6.2/ruby/2.6.0/gems/github-linguist-7.4.0.32.g7f67bc95/lib/linguist/blob_helper.rb:56:in `binary_mime_type?'
    /var/lib/jenkins/workspace/github/vendor/gems/2.6.2/ruby/2.6.0/gems/github-linguist-7.4.0.32.g7f67bc95/lib/linguist/blob_helper.rb:79:in `content_type'
[...]

This PR fixes issue by forcing the name to always be a string, even if nil.

[ Checklist removed as it doesn't apply ]

/cc @ksolo

@pchaigno
Copy link
Contributor

pchaigno commented Jun 4, 2019

We don't have tests for this?

@lildude
Copy link
Member Author

lildude commented Jun 4, 2019

We don't have tests for this?

Clearly not 😉. I'll see if I can come up with a good test.

@lildude
Copy link
Member Author

lildude commented Jun 4, 2019

And now with a test 😁

Copy link
Contributor

@pchaigno pchaigno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lildude lildude merged commit a0e8b87 into master Jun 4, 2019
@lildude lildude deleted the lildude/fix-mime_type branch June 4, 2019 09:18
@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants