Improve Pathname#text_executable? regexp
file(1) does not allow leading whitespace on shebang lines, and there appears to be no restrictions on what characters follow '#!', either. While at it, fix an erroneous shebang test. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
1b6f23c8a9
commit
7002359f7a
@ -272,7 +272,7 @@ class Pathname
|
|||||||
end
|
end
|
||||||
|
|
||||||
def text_executable?
|
def text_executable?
|
||||||
%r[#!\s*(/.+)+] === open('r') { |f| f.readline }
|
%r[^#!\s*.+] === open('r') { |f| f.readline }
|
||||||
rescue EOFError
|
rescue EOFError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@ -135,7 +135,7 @@ class TextExecutableTests < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_malformed_shebang
|
def test_malformed_shebang
|
||||||
pn = Pathname.new('baz')
|
pn = Pathname.new('baz')
|
||||||
pn.write '#! '
|
pn.write ' #!'
|
||||||
assert !pn.universal?
|
assert !pn.universal?
|
||||||
assert !pn.i386?
|
assert !pn.i386?
|
||||||
assert !pn.x86_64?
|
assert !pn.x86_64?
|
||||||
@ -146,7 +146,7 @@ class TextExecutableTests < Test::Unit::TestCase
|
|||||||
assert !pn.text_executable?
|
assert !pn.text_executable?
|
||||||
assert_equal [], pn.archs
|
assert_equal [], pn.archs
|
||||||
assert pn.arch == :dunno
|
assert pn.arch == :dunno
|
||||||
assert_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
|
assert_no_match /text executable/, `/usr/bin/file -h '#{pn}'`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user