From ec3434cf1d0d02a8fbc61a7c8038970c01b94227 Mon Sep 17 00:00:00 2001 From: Ben Lavender Date: Sun, 18 Nov 2012 20:56:06 -0600 Subject: [PATCH] Don't explode on invalid shebang --- lib/linguist/samples.json | 12 ++++++------ lib/linguist/tokenizer.rb | 2 +- samples/Shell/invalid-shebang.sh | 3 +++ test/test_tokenizer.rb | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 samples/Shell/invalid-shebang.sh diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index 63a40762..a6a3c827 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -260,8 +260,8 @@ ".gemrc" ] }, - "tokens_total": 271187, - "languages_total": 275, + "tokens_total": 271188, + "languages_total": 276, "tokens": { "Apex": { "global": 70, @@ -25252,7 +25252,7 @@ }, "Shell": { "SHEBANG#!bash": 6, - "echo": 52, + "echo": 53, "export": 6, "PATH": 5, "pkgname": 1, @@ -27795,7 +27795,7 @@ "Scheme": 3478, "Scilab": 69, "SCSS": 39, - "Shell": 2008, + "Shell": 2009, "Standard ML": 243, "SuperCollider": 135, "Tea": 3, @@ -27866,7 +27866,7 @@ "Scheme": 1, "Scilab": 3, "SCSS": 1, - "Shell": 16, + "Shell": 17, "Standard ML": 2, "SuperCollider": 1, "Tea": 1, @@ -27881,5 +27881,5 @@ "XSLT": 1, "YAML": 1 }, - "md5": "8591cfa68ab6fe3b3dacbcb885be70d0" + "md5": "384f02c0bd223479bf750d4cd36daf71" } \ No newline at end of file diff --git a/lib/linguist/tokenizer.rb b/lib/linguist/tokenizer.rb index fcd88efc..c600f7af 100644 --- a/lib/linguist/tokenizer.rb +++ b/lib/linguist/tokenizer.rb @@ -138,7 +138,7 @@ module Linguist s.scan(/\s+/) script = s.scan(/\S+/) end - script = script[/[^\d]+/, 0] + script = script[/[^\d]+/, 0] if script return script end diff --git a/samples/Shell/invalid-shebang.sh b/samples/Shell/invalid-shebang.sh new file mode 100644 index 00000000..5a87011c --- /dev/null +++ b/samples/Shell/invalid-shebang.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env + +echo "wat" diff --git a/test/test_tokenizer.rb b/test/test_tokenizer.rb index af649204..27dde635 100644 --- a/test/test_tokenizer.rb +++ b/test/test_tokenizer.rb @@ -94,6 +94,7 @@ class TestTokenizer < Test::Unit::TestCase assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby.script!")[0] assert_equal "SHEBANG#!ruby", tokenize(:"Ruby/ruby2.script!")[0] assert_equal "SHEBANG#!node", tokenize(:"JavaScript/js.script!")[0] + assert_equal "echo", tokenize(:"Shell/invalid-shebang.sh")[0] end def test_javascript_tokens