diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index 89a0df2f..4d549cc9 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -95,7 +95,7 @@ module Linguist # Returns sorted Array of result pairs. Each pair contains the # String language name and a Float score. def classify(tokens, languages) - return [] if tokens.nil? + return [] if tokens.nil? || languages.empty? tokens = Tokenizer.tokenize(tokens) if tokens.is_a?(String) scores = {} diff --git a/test/test_classifier.rb b/test/test_classifier.rb index 2ae2f45e..818bee29 100644 --- a/test/test_classifier.rb +++ b/test/test_classifier.rb @@ -53,4 +53,8 @@ class TestClassifier < Minitest::Test assert_equal language.name, results.first[0], "#{sample[:path]}\n#{results.inspect}" end end + + def test_classify_empty_languages + assert_equal [], Classifier.classify(Samples.cache, fixture("Ruby/foo.rb"), []) + end end