updating github.com/mattn/go-shellwords to v1.0.5

This commit is contained in:
Davanum Srinivas
2019-06-14 11:09:05 -04:00
parent b713287e43
commit 1a5cfb7aca
5 changed files with 30 additions and 12 deletions

1
vendor/github.com/mattn/go-shellwords/go.mod generated vendored Normal file
View File

@@ -0,0 +1 @@
module github.com/mattn/go-shellwords

View File

@@ -4,6 +4,7 @@ import (
"errors"
"os"
"regexp"
"strings"
)
var (
@@ -21,13 +22,17 @@ func isSpace(r rune) bool {
return false
}
func replaceEnv(s string) string {
func replaceEnv(getenv func(string) string, s string) string {
if getenv == nil {
getenv = os.Getenv
}
return envRe.ReplaceAllStringFunc(s, func(s string) string {
s = s[1:]
if s[0] == '{' {
s = s[1 : len(s)-1]
}
return os.Getenv(s)
return getenv(s)
})
}
@@ -35,10 +40,18 @@ type Parser struct {
ParseEnv bool
ParseBacktick bool
Position int
// If ParseEnv is true, use this for getenv.
// If nil, use os.Getenv.
Getenv func(string) string
}
func NewParser() *Parser {
return &Parser{ParseEnv, ParseBacktick, 0}
return &Parser{
ParseEnv: ParseEnv,
ParseBacktick: ParseBacktick,
Position: 0,
}
}
func (p *Parser) Parse(line string) ([]string, error) {
@@ -73,7 +86,7 @@ loop:
backtick += string(r)
} else if got {
if p.ParseEnv {
buf = replaceEnv(buf)
buf = replaceEnv(p.Getenv, buf)
}
args = append(args, buf)
buf = ""
@@ -108,7 +121,11 @@ loop:
if err != nil {
return nil, err
}
buf = out
if r == ')' {
buf = buf[:len(buf)-len(backtick)-2] + out
} else {
buf = buf[:len(buf)-len(backtick)-1] + out
}
}
backtick = ""
dollarQuote = !dollarQuote
@@ -119,7 +136,7 @@ loop:
}
case '(':
if !singleQuoted && !doubleQuoted && !backQuote {
if !dollarQuote && len(buf) > 0 && buf == "$" {
if !dollarQuote && strings.HasSuffix(buf, "$") {
dollarQuote = true
buf += "("
continue
@@ -159,7 +176,7 @@ loop:
if got {
if p.ParseEnv {
buf = replaceEnv(buf)
buf = replaceEnv(p.Getenv, buf)
}
args = append(args, buf)
}