Check for multiline shebang script hacks

Fixes #8
This commit is contained in:
Joshua Peek
2011-06-27 17:35:48 -05:00
parent 19720117a1
commit ebba204ba3
4 changed files with 31 additions and 1 deletions

View File

@@ -308,7 +308,7 @@ module Linguist
# Fail fast if blob isn't viewable?
return unless viewable?
if data && (match = data.match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
if data && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
bang.sub!(/^#! /, '#!')
tokens = bang.split(' ')
pieces = tokens.first.split('/')
@@ -325,6 +325,16 @@ module Linguist
script.sub! $1, ''
end
# Check for multiline shebang hacks that exec themselves
#
# #!/bin/sh
# exec foo "$0" "$@"
#
if script == 'sh' &&
lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
script = $1
end
script
end
end