diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 3011bb83..71c2b520 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -470,7 +470,7 @@ module Linguist Language['Objective-C'] # Matlab file function or class or comments - elsif lines.first.grep(/^\s*(function |classdef )/).any? || lines.grep(/^\s*%/).any? + elsif lines.any? && lines.first.grep(/^\s*(function |classdef )/).any? || lines.grep(/^\s*%/).any? Language['Matlab'] # Fallback to Objective-C, don't want any Matlab false positives diff --git a/test/fixtures/empty.m b/test/fixtures/empty.m new file mode 100644 index 00000000..e69de29b diff --git a/test/test_blob.rb b/test/test_blob.rb index 9f2003c3..59c02571 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -307,6 +307,7 @@ class TestBlob < Test::Unit::TestCase assert_equal Language['Perl'], blob("test-perl2.pl").language # .m disambiguation + assert_equal Language['Objective-C'], blob("empty.m").language assert_equal Language['Objective-C'], blob("Foo.m").language assert_equal Language['Objective-C'], blob("hello.m").language assert_equal Language['Matlab'], blob("matlab_function.m").language