Skip to content

Commit

Permalink
Force name to be string when looking up mime type (#4545)
Browse files Browse the repository at this point in the history
* Always pass name as string, even if nil

* Update comment

* Add nil filename test
  • Loading branch information
lildude authored Jun 4, 2019
1 parent 9847fcf commit a0e8b87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/linguist/blob_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def extname
File.extname(name.to_s)
end

# Internal: Lookup mime type for extension.
# Internal: Lookup mime type for filename.
#
# Returns a MIME::Type
def _mime_type
if defined? @_mime_type
@_mime_type
else
@_mime_type = MiniMime.lookup_by_filename(name)
@_mime_type = MiniMime.lookup_by_filename(name.to_s)
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/test_file_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def test_mime_type
assert_equal "application/xml", sample_blob("XML/bar.xml").mime_type
assert_equal "audio/ogg", fixture_blob("Binary/foo.ogg").mime_type
assert_equal "text/plain", fixture_blob("Data/README").mime_type
# GitHub doesn't use a filename when returning raw blobs
blob = Struct.new(:name) { include Linguist::BlobHelper }
assert_equal "text/plain", blob.new(nil).mime_type
end

def test_content_type
Expand Down

0 comments on commit a0e8b87

Please sign in to comment.