From 35fe44549e916def62db34827cd5648d589654b9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 9 May 2012 09:52:14 -0500 Subject: [PATCH] Fix empty .m file --- lib/linguist/blob_helper.rb | 2 +- test/fixtures/empty.m | 0 test/test_blob.rb | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/empty.m 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