Place guards, checks for multiline shell hacks

This commit is contained in:
Ted Nyman 2013-12-06 20:39:02 -08:00
Родитель 8603760ebe
Коммит 7e178cc416
5 изменённых файлов: 18 добавлений и 14 удалений

Просмотреть файл

@ -190,9 +190,9 @@ module Linguist
# Public: Is the blob safe to colorize?
#
# We use Pygments for syntax highlighting blobs. Pygments
# can be too slow for very large blobs or for certain
# can be too slow for very large blobs or for certain
# corner-case blobs.
#
#
# Return true or false
def safe_to_colorize?
!large? && text? && !high_ratio_of_long_lines?

Просмотреть файл

@ -110,10 +110,10 @@ module Linguist
data = data.call() if data.respond_to?(:call)
if data.nil? || data == ""
nil
elsif result = find_by_shebang(data)
elsif (result = find_by_shebang(data)) && !result.empty?
result.first
elsif result = Classifier.classify(Samples::DATA, data, possible_languages.map(&:name)).first
Language[result[0]]
elsif classified = Classifier.classify(Samples::DATA, data, possible_languages.map(&:name)).first
Language[classified[0]]
end
else
possible_languages.first

Просмотреть файл

@ -421,6 +421,9 @@
"Xtend": [
".xtend"
]
},
"interpreters": {
},
"filenames": {
"ApacheConf": [
@ -43881,5 +43884,5 @@
"Xtend": 2,
"YAML": 1
},
"md5": "647da23cd1eb02653f50ff9bfbb6e70d"
"md5": "9ef710bbe7098e21726a69720f0922b5"
}

Просмотреть файл

@ -114,7 +114,7 @@ module Linguist
# Used to retrieve the interpreter from the shebang line of a file's
# data.
def self.interpreter_from_shebang(data)
lines = data.lines
lines = data.lines.to_a
if lines.any? && (match = lines[0].match(/(.+)\n?/)) && (bang = match[0]) =~ /^#!/
bang.sub!(/^#! /, '#!')
@ -134,7 +134,15 @@ module Linguist
script.sub! $1, ''
end
# Check for multiline shebang hacks that call `exec`
if script == 'sh' &&
lines[0...5].any? { |l| l.match(/exec (\w+).+\$0.+\$@/) }
script = $1
end
script
else
nil
end
end

Просмотреть файл

@ -1,7 +0,0 @@
#!/bin/sh
#| -*- scheme -*-
exec racket -um "$0" "$@"
|#
(require racket/file racket/path racket/list racket/string
(for-syntax racket/base))