Don't explode on invalid shebang

This commit is contained in:
Ben Lavender
2012-11-18 20:56:06 -06:00
parent d92d208a45
commit ec3434cf1d
4 changed files with 11 additions and 7 deletions

View File

@@ -260,8 +260,8 @@
".gemrc" ".gemrc"
] ]
}, },
"tokens_total": 271187, "tokens_total": 271188,
"languages_total": 275, "languages_total": 276,
"tokens": { "tokens": {
"Apex": { "Apex": {
"global": 70, "global": 70,
@@ -25252,7 +25252,7 @@
}, },
"Shell": { "Shell": {
"SHEBANG#!bash": 6, "SHEBANG#!bash": 6,
"echo": 52, "echo": 53,
"export": 6, "export": 6,
"PATH": 5, "PATH": 5,
"pkgname": 1, "pkgname": 1,
@@ -27795,7 +27795,7 @@
"Scheme": 3478, "Scheme": 3478,
"Scilab": 69, "Scilab": 69,
"SCSS": 39, "SCSS": 39,
"Shell": 2008, "Shell": 2009,
"Standard ML": 243, "Standard ML": 243,
"SuperCollider": 135, "SuperCollider": 135,
"Tea": 3, "Tea": 3,
@@ -27866,7 +27866,7 @@
"Scheme": 1, "Scheme": 1,
"Scilab": 3, "Scilab": 3,
"SCSS": 1, "SCSS": 1,
"Shell": 16, "Shell": 17,
"Standard ML": 2, "Standard ML": 2,
"SuperCollider": 1, "SuperCollider": 1,
"Tea": 1, "Tea": 1,
@@ -27881,5 +27881,5 @@
"XSLT": 1, "XSLT": 1,
"YAML": 1 "YAML": 1
}, },
"md5": "8591cfa68ab6fe3b3dacbcb885be70d0" "md5": "384f02c0bd223479bf750d4cd36daf71"
} }

View File

@@ -138,7 +138,7 @@ module Linguist
s.scan(/\s+/) s.scan(/\s+/)
script = s.scan(/\S+/) script = s.scan(/\S+/)
end end
script = script[/[^\d]+/, 0] script = script[/[^\d]+/, 0] if script
return script return script
end end

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env
echo "wat"

View File

@@ -94,6 +94,7 @@ class TestTokenizer < Test::Unit::TestCase
assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby.script!")[0] assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby.script!")[0]
assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby2.script!")[0] assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby2.script!")[0]
assert_equal "SHEBANG#!node", tokenize(:"JavaScript/js.script!")[0] assert_equal "SHEBANG#!node", tokenize(:"JavaScript/js.script!")[0]
assert_equal "echo", tokenize(:"Shell/invalid-shebang.sh")[0]
end end
def test_javascript_tokens def test_javascript_tokens