mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-25 02:35:34 +00:00
Default to not binary
This commit is contained in:
@@ -88,7 +88,7 @@ module Linguist
|
|||||||
# Returns true or false
|
# Returns true or false
|
||||||
def self.binary?(ext_or_mime_type)
|
def self.binary?(ext_or_mime_type)
|
||||||
mime_type = lookup_mime_type_for(ext_or_mime_type)
|
mime_type = lookup_mime_type_for(ext_or_mime_type)
|
||||||
mime_type.nil? || mime_type.binary?
|
mime_type ? mime_type.binary? : false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Internal: Lookup mime type for extension or mime type
|
# Internal: Lookup mime type for extension or mime type
|
||||||
|
|||||||
@@ -49,11 +49,43 @@ application/x-wais-source:
|
|||||||
application/vnd.mozilla.xul+xml:
|
application/vnd.mozilla.xul+xml:
|
||||||
binary: false
|
binary: false
|
||||||
|
|
||||||
|
application/vnd.adobe.air-application-installer-package+zip:
|
||||||
|
binary: true
|
||||||
|
extensions:
|
||||||
|
- air
|
||||||
|
|
||||||
application/octet-stream:
|
application/octet-stream:
|
||||||
binary: true
|
binary: true
|
||||||
extensions:
|
extensions:
|
||||||
- dmg
|
# TODO: Lookup actual content type for these extensions
|
||||||
|
- a
|
||||||
|
- blend
|
||||||
- dll
|
- dll
|
||||||
|
- dmg
|
||||||
|
- gem
|
||||||
|
- graffle
|
||||||
|
- ipa
|
||||||
|
- lib
|
||||||
|
- mcz
|
||||||
|
- nib
|
||||||
|
- o
|
||||||
|
- odp
|
||||||
|
- ods
|
||||||
|
- odt
|
||||||
|
- otf
|
||||||
|
- ogv
|
||||||
|
- pfx
|
||||||
|
- pigx
|
||||||
|
- plgx
|
||||||
|
- pptx
|
||||||
|
- psd
|
||||||
|
- sib
|
||||||
|
- so
|
||||||
|
- spl
|
||||||
|
- sqlite3
|
||||||
|
- swc
|
||||||
|
- ucode
|
||||||
|
- xpi
|
||||||
|
|
||||||
application/java-archive:
|
application/java-archive:
|
||||||
binary: true
|
binary: true
|
||||||
@@ -61,6 +93,16 @@ application/java-archive:
|
|||||||
- ear
|
- ear
|
||||||
- war
|
- war
|
||||||
|
|
||||||
|
application/x-chrome-extension:
|
||||||
|
binary: true
|
||||||
|
extensions:
|
||||||
|
- crx
|
||||||
|
|
||||||
|
application/x-debian-package:
|
||||||
|
binary: true
|
||||||
|
extensions:
|
||||||
|
- deb
|
||||||
|
|
||||||
application/x-shockwave-flash:
|
application/x-shockwave-flash:
|
||||||
binary: true
|
binary: true
|
||||||
extensions:
|
extensions:
|
||||||
@@ -74,3 +116,18 @@ image/jpeg:
|
|||||||
|
|
||||||
image/png:
|
image/png:
|
||||||
attachment: false
|
attachment: false
|
||||||
|
|
||||||
|
image/x-icns:
|
||||||
|
binary: true
|
||||||
|
extensions:
|
||||||
|
- icns
|
||||||
|
|
||||||
|
text/cache-manifest:
|
||||||
|
extensions:
|
||||||
|
- manifest
|
||||||
|
|
||||||
|
video/quicktime:
|
||||||
|
binary: true
|
||||||
|
extensions:
|
||||||
|
- qt
|
||||||
|
- mov
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
def test_mime_type
|
def test_mime_type
|
||||||
assert_equal "application/ruby", blob("grit.rb").mime_type
|
assert_equal "application/ruby", blob("grit.rb").mime_type
|
||||||
assert_equal "application/xml", blob("bar.xml").mime_type
|
assert_equal "application/xml", blob("bar.xml").mime_type
|
||||||
assert_equal "text/plain", blob("dog.o").mime_type
|
assert_equal "application/octet-stream", blob("dog.o").mime_type
|
||||||
assert_equal "application/sh", blob("script.sh").mime_type
|
assert_equal "application/sh", blob("script.sh").mime_type
|
||||||
|
assert_equal "text/plain", blob("README").mime_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_content_type
|
def test_content_type
|
||||||
@@ -35,6 +36,7 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal "text/plain; charset=utf-8", blob("bar.xml").content_type
|
assert_equal "text/plain; charset=utf-8", blob("bar.xml").content_type
|
||||||
assert_equal "application/octet-stream", blob("dog.o").content_type
|
assert_equal "application/octet-stream", blob("dog.o").content_type
|
||||||
assert_equal "text/plain; charset=utf-8", blob("script.sh").content_type
|
assert_equal "text/plain; charset=utf-8", blob("script.sh").content_type
|
||||||
|
assert_equal "text/plain; charset=utf-8", blob("README").content_type
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_disposition
|
def test_disposition
|
||||||
@@ -43,6 +45,7 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal "attachment; filename=foo+bar.jar", blob("foo bar.jar").disposition
|
assert_equal "attachment; filename=foo+bar.jar", blob("foo bar.jar").disposition
|
||||||
assert_equal "inline", blob("foo.txt").disposition
|
assert_equal "inline", blob("foo.txt").disposition
|
||||||
assert_equal "inline", blob("grit.rb").disposition
|
assert_equal "inline", blob("grit.rb").disposition
|
||||||
|
assert_equal "inline", blob("README").disposition
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_data
|
def test_data
|
||||||
@@ -69,6 +72,7 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert blob("linguist.gem").binary?
|
assert blob("linguist.gem").binary?
|
||||||
assert blob("git.deb").binary?
|
assert blob("git.deb").binary?
|
||||||
assert blob("git.exe").binary?
|
assert blob("git.exe").binary?
|
||||||
|
assert !blob("README").binary?
|
||||||
assert !blob("file.txt").binary?
|
assert !blob("file.txt").binary?
|
||||||
assert !blob("foo.rb").binary?
|
assert !blob("foo.rb").binary?
|
||||||
assert !blob("octocat.png").binary?
|
assert !blob("octocat.png").binary?
|
||||||
@@ -76,8 +80,9 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_text
|
def test_text
|
||||||
assert blob("file.txt").text?
|
assert blob("README").text?
|
||||||
assert blob("file.json").text?
|
assert blob("file.json").text?
|
||||||
|
assert blob("file.txt").text?
|
||||||
assert blob("script.sh").text?
|
assert blob("script.sh").text?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -90,10 +95,11 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_viewable
|
def test_viewable
|
||||||
|
assert blob("README").viewable?
|
||||||
assert blob("foo.rb").viewable?
|
assert blob("foo.rb").viewable?
|
||||||
assert blob("script.pl").viewable?
|
assert blob("script.pl").viewable?
|
||||||
assert !blob("octocat.png").viewable?
|
|
||||||
assert !blob("linguist.gem").viewable?
|
assert !blob("linguist.gem").viewable?
|
||||||
|
assert !blob("octocat.png").viewable?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_generated
|
def test_generated
|
||||||
@@ -210,6 +216,8 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert_equal Language['VimL'], blob(".gvimrc").language
|
assert_equal Language['VimL'], blob(".gvimrc").language
|
||||||
assert_equal Language['INI'], blob(".gitconfig").language
|
assert_equal Language['INI'], blob(".gitconfig").language
|
||||||
assert_equal Language['YAML'], blob(".gemrc").language
|
assert_equal Language['YAML'], blob(".gemrc").language
|
||||||
|
|
||||||
|
assert_equal Language['Text'], blob("README").language
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lexer
|
def test_lexer
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class TestMime < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_mime
|
def test_mime
|
||||||
assert_equal 'text/plain', Mime.mime_for(nil)
|
assert_equal 'text/plain', Mime.mime_for(nil)
|
||||||
|
assert_equal 'text/plain', Mime.mime_for("")
|
||||||
|
|
||||||
assert_equal 'application/ruby', Mime.mime_for(".rb")
|
assert_equal 'application/ruby', Mime.mime_for(".rb")
|
||||||
assert_equal 'application/javascript', Mime.mime_for(".js")
|
assert_equal 'application/javascript', Mime.mime_for(".js")
|
||||||
@@ -14,11 +15,19 @@ class TestMime < Test::Unit::TestCase
|
|||||||
|
|
||||||
assert_equal 'text/plain', Mime.mime_for(".kt")
|
assert_equal 'text/plain', Mime.mime_for(".kt")
|
||||||
assert_equal 'text/html', Mime.mime_for(".html")
|
assert_equal 'text/html', Mime.mime_for(".html")
|
||||||
|
assert_equal 'text/cache-manifest', Mime.mime_for(".manifest")
|
||||||
assert_equal 'application/sh', Mime.mime_for(".sh")
|
assert_equal 'application/sh', Mime.mime_for(".sh")
|
||||||
assert_equal 'application/latex', Mime.mime_for(".latex")
|
assert_equal 'application/latex', Mime.mime_for(".latex")
|
||||||
|
|
||||||
|
assert_equal 'application/vnd.adobe.air-application-installer-package+zip',
|
||||||
|
Mime.mime_for(".air")
|
||||||
assert_equal 'application/shockwave-flash', Mime.mime_for(".swf")
|
assert_equal 'application/shockwave-flash', Mime.mime_for(".swf")
|
||||||
|
|
||||||
|
assert_equal 'application/chrome-extension', Mime.mime_for(".crx")
|
||||||
|
assert_equal 'application/debian-package', Mime.mime_for(".deb")
|
||||||
|
|
||||||
|
assert_equal 'video/quicktime', Mime.mime_for(".mov")
|
||||||
|
|
||||||
assert_equal 'application/octet-stream', Mime.mime_for(".dmg")
|
assert_equal 'application/octet-stream', Mime.mime_for(".dmg")
|
||||||
assert_equal 'application/octet-stream', Mime.mime_for(".exe")
|
assert_equal 'application/octet-stream', Mime.mime_for(".exe")
|
||||||
assert_equal 'application/octet-stream', Mime.mime_for(".dll")
|
assert_equal 'application/octet-stream', Mime.mime_for(".dll")
|
||||||
@@ -30,6 +39,7 @@ class TestMime < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_content_type
|
def test_content_type
|
||||||
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(nil)
|
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(nil)
|
||||||
|
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for("")
|
||||||
|
|
||||||
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".rb")
|
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".rb")
|
||||||
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".js")
|
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".js")
|
||||||
@@ -40,10 +50,11 @@ class TestMime < Test::Unit::TestCase
|
|||||||
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".sh")
|
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".sh")
|
||||||
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".latex")
|
assert_equal 'text/plain; charset=utf-8', Mime.content_type_for(".latex")
|
||||||
|
|
||||||
assert_equal 'application/octet-stream', Mime.content_type_for(".swf")
|
assert_equal 'application/octet-stream', Mime.content_type_for(".air")
|
||||||
|
assert_equal 'application/octet-stream', Mime.content_type_for(".dll")
|
||||||
assert_equal 'application/octet-stream', Mime.content_type_for(".dmg")
|
assert_equal 'application/octet-stream', Mime.content_type_for(".dmg")
|
||||||
assert_equal 'application/octet-stream', Mime.content_type_for(".exe")
|
assert_equal 'application/octet-stream', Mime.content_type_for(".exe")
|
||||||
assert_equal 'application/octet-stream', Mime.content_type_for(".dll")
|
assert_equal 'application/octet-stream', Mime.content_type_for(".swf")
|
||||||
|
|
||||||
assert_equal 'application/java-archive', Mime.content_type_for(".jar")
|
assert_equal 'application/java-archive', Mime.content_type_for(".jar")
|
||||||
assert_equal 'application/java-archive', Mime.content_type_for(".ear")
|
assert_equal 'application/java-archive', Mime.content_type_for(".ear")
|
||||||
@@ -51,6 +62,9 @@ class TestMime < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_binary
|
def test_binary
|
||||||
|
assert !Mime.binary?(nil)
|
||||||
|
assert !Mime.binary?("")
|
||||||
|
|
||||||
assert Mime.binary?("application/octet-stream")
|
assert Mime.binary?("application/octet-stream")
|
||||||
assert !Mime.binary?("text/plain")
|
assert !Mime.binary?("text/plain")
|
||||||
|
|
||||||
@@ -58,13 +72,12 @@ class TestMime < Test::Unit::TestCase
|
|||||||
assert Mime.binary?("application/ogg")
|
assert Mime.binary?("application/ogg")
|
||||||
assert Mime.binary?("application/pdf")
|
assert Mime.binary?("application/pdf")
|
||||||
assert Mime.binary?("application/x-gzip")
|
assert Mime.binary?("application/x-gzip")
|
||||||
|
assert Mime.binary?("application/x-shockwave-flash")
|
||||||
assert Mime.binary?("application/zip")
|
assert Mime.binary?("application/zip")
|
||||||
assert Mime.binary?("audio/mp4")
|
assert Mime.binary?("audio/mp4")
|
||||||
assert Mime.binary?("image/gif")
|
assert Mime.binary?("image/gif")
|
||||||
assert Mime.binary?("image/jpeg")
|
assert Mime.binary?("image/jpeg")
|
||||||
assert Mime.binary?("image/png")
|
assert Mime.binary?("image/png")
|
||||||
assert Mime.binary?("java-archive")
|
|
||||||
assert Mime.binary?("x-shockwave-flash")
|
|
||||||
|
|
||||||
assert Mime.binary?(".a")
|
assert Mime.binary?(".a")
|
||||||
assert Mime.binary?(".air")
|
assert Mime.binary?(".air")
|
||||||
|
|||||||
Reference in New Issue
Block a user