From afac6a918d84a8c8e14165bf6ea0ca1edd7a482c Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Wed, 10 Dec 2014 11:00:32 -0500 Subject: [PATCH] Handle empty shebang with whitespace --- lib/linguist/shebang.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/linguist/shebang.rb b/lib/linguist/shebang.rb index 3405bb62..07694667 100644 --- a/lib/linguist/shebang.rb +++ b/lib/linguist/shebang.rb @@ -19,11 +19,12 @@ module Linguist # Returns a String or nil def self.interpreter(data) lines = data.lines - return unless match = /^#! ?(.+)$/.match(lines.first) - tokens = match[1].split(' ') - script = tokens.first.split('/').last + return unless match = /^#!(.+)$/.match(lines.first) + tokens = match[1].strip.split(' ') + return if tokens.empty? + script = File.basename(tokens.first) script = tokens[1] if script == 'env' # If script has an invalid shebang, we might get here