mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-24 16:21:14 -03:00
Fixed GetLanguagesByShebang for paths with “env”
This commit is contained in:
parent
335b4a64d8
commit
58f8dccbcf
17
common.go
17
common.go
@ -3,6 +3,7 @@ package enry
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -314,13 +315,17 @@ func getInterpreter(data []byte) (interpreter string) {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Contains(splitted[0], []byte("env")) {
|
// Extract interpreter name from path. Use path.Base because
|
||||||
if len(splitted) > 1 {
|
// shebang on Cygwin/Windows still use a forward slash
|
||||||
interpreter = string(splitted[1])
|
interpreter = path.Base(string(splitted[0]))
|
||||||
|
|
||||||
|
// #!/usr/bin/env [...]
|
||||||
|
if interpreter == "env" {
|
||||||
|
if len(splitted) == 1 {
|
||||||
|
// /usr/bin/env with no arguments
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
} else {
|
interpreter = path.Base(string(splitted[1]))
|
||||||
splittedPath := bytes.Split(splitted[0], []byte{'/'})
|
|
||||||
interpreter = string(splittedPath[len(splittedPath)-1])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if interpreter == "sh" {
|
if interpreter == "sh" {
|
||||||
|
@ -296,7 +296,8 @@ println("The shell script says ",vm.arglist.concat(" "));`
|
|||||||
{name: "TestGetLanguagesByShebang_8", content: []byte(`#!bash`), expected: []string{"Shell"}},
|
{name: "TestGetLanguagesByShebang_8", content: []byte(`#!bash`), expected: []string{"Shell"}},
|
||||||
{name: "TestGetLanguagesByShebang_9", content: []byte(multilineExecHack), expected: []string{"Tcl"}},
|
{name: "TestGetLanguagesByShebang_9", content: []byte(multilineExecHack), expected: []string{"Tcl"}},
|
||||||
{name: "TestGetLanguagesByShebang_10", content: []byte(multilineNoExecHack), expected: []string{"Shell"}},
|
{name: "TestGetLanguagesByShebang_10", content: []byte(multilineNoExecHack), expected: []string{"Shell"}},
|
||||||
{name: "TestGetLanguagesByShebang_11", content: []byte(`#!`), expected: nil},
|
{name: "TestGetLanguagesByShebang_11", content: []byte(`#!/envinpath/python`), expected: []string{"Python"}},
|
||||||
|
{name: "TestGetLanguagesByShebang_12", content: []byte(`#!`), expected: nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user