From d8798c2dd91524c21ea5a5ed03a806642ffa4d85 Mon Sep 17 00:00:00 2001 From: Manuel Carmona Date: Tue, 4 Jul 2017 11:22:01 +0200 Subject: [PATCH] binary files are returned as OtherLanguage by GetLanguage --- common.go | 4 ++++ common_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/common.go b/common.go index ed1e6d8..b299d36 100644 --- a/common.go +++ b/common.go @@ -116,6 +116,10 @@ func GetLanguageBySpecificClassifier(content []byte, candidates []string, classi // GetLanguages applies a sequence of strategies based on the given filename and content // to find out the most probably languages to return. func GetLanguages(filename string, content []byte) []string { + if IsBinary(content) { + return nil + } + var languages []string candidates := []string{} for _, strategy := range DefaultStrategies { diff --git a/common_test.go b/common_test.go index ca83e09..208767d 100644 --- a/common_test.go +++ b/common_test.go @@ -64,6 +64,7 @@ func (s *EnryTestSuite) TestGetLanguage() { {name: "TestGetLanguage_1", filename: "foo.py", content: []byte{}, expected: "Python"}, {name: "TestGetLanguage_2", filename: "foo.m", content: []byte(":- module"), expected: "Mercury"}, {name: "TestGetLanguage_3", filename: "foo.m", content: nil, expected: OtherLanguage}, + {name: "TestGetLanguage_4", filename: "foo.mo", content: []byte{0xDE, 0x12, 0x04, 0x95, 0x00, 0x00, 0x00, 0x00}, expected: OtherLanguage}, } for _, test := range tests {