From 3303cf782421cda0cbec10888759477f6b25d650 Mon Sep 17 00:00:00 2001 From: Alexander Bezzubov Date: Tue, 25 Jul 2017 10:25:43 +0200 Subject: [PATCH] Fix :bug: on file starting with single shebang --- common.go | 6 ++++-- common_test.go | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/common.go b/common.go index b299d36..937285a 100644 --- a/common.go +++ b/common.go @@ -284,14 +284,16 @@ func getInterpreter(data []byte) (interpreter string) { // skip shebang line = bytes.TrimSpace(line[2:]) - splitted := bytes.Fields(line) + if len(splitted) == 0 { + return "" + } + if bytes.Contains(splitted[0], []byte("env")) { if len(splitted) > 1 { interpreter = string(splitted[1]) } } else { - splittedPath := bytes.Split(splitted[0], []byte{'/'}) interpreter = string(splittedPath[len(splittedPath)-1]) } diff --git a/common_test.go b/common_test.go index 6e83115..8c53a6f 100644 --- a/common_test.go +++ b/common_test.go @@ -212,6 +212,7 @@ println("The shell script says ",vm.arglist.concat(" "));` {name: "TestGetLanguagesByShebang_8", content: []byte(`#!bash`), expected: []string{"Shell"}}, {name: "TestGetLanguagesByShebang_9", content: []byte(multilineExecHack), expected: []string{"Tcl"}}, {name: "TestGetLanguagesByShebang_10", content: []byte(multilineNoExecHack), expected: []string{"Shell"}}, + {name: "TestGetLanguagesByShebang_11", content: []byte(`#!`), expected: nil}, } for _, test := range tests {