diff --git a/go.mod b/go.mod index 0e570eb40c6..136ba70d953 100644 --- a/go.mod +++ b/go.mod @@ -96,7 +96,7 @@ require ( github.com/lithammer/dedent v1.1.0 github.com/lpabon/godbc v0.1.1 // indirect github.com/magiconair/properties v1.8.1 // indirect - github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de // indirect + github.com/mattn/go-shellwords v1.0.5 // indirect github.com/mesos/mesos-go v0.0.9 // indirect github.com/mholt/caddy v0.0.0-20180213163048-2de495001514 github.com/miekg/dns v0.0.0-20160614162101-5d001d020961 @@ -323,7 +323,7 @@ replace ( github.com/magiconair/properties => github.com/magiconair/properties v1.8.1 github.com/mailru/easyjson => github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 github.com/marstr/guid => github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c - github.com/mattn/go-shellwords => github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de + github.com/mattn/go-shellwords => github.com/mattn/go-shellwords v1.0.5 github.com/matttproud/golang_protobuf_extensions => github.com/matttproud/golang_protobuf_extensions v1.0.1 github.com/mesos/mesos-go => github.com/mesos/mesos-go v0.0.9 github.com/mholt/caddy => github.com/mholt/caddy v0.0.0-20180213163048-2de495001514 diff --git a/go.sum b/go.sum index 1c923d2482f..51edef85157 100644 --- a/go.sum +++ b/go.sum @@ -255,8 +255,8 @@ github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3 github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c h1:N7uWGS2fTwH/4BwxbHiJZNAFTSJ5yPU0emHsQWvkxEY= github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= -github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de h1:ryDLMbZGgf2bSdLfdQFaJuuP4No40cDUt62Mdv+3TW8= -github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= +github.com/mattn/go-shellwords v1.0.5 h1:JhhFTIOslh5ZsPrpa3Wdg8bF0WI3b44EMblmU9wIsXc= +github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mesos/mesos-go v0.0.9 h1:w8V5sOEnxzHZ2kAOy273v/HgbolyI6XI+qe5jx5u+Y0= diff --git a/vendor/github.com/mattn/go-shellwords/go.mod b/vendor/github.com/mattn/go-shellwords/go.mod new file mode 100644 index 00000000000..8d96dbd5fa3 --- /dev/null +++ b/vendor/github.com/mattn/go-shellwords/go.mod @@ -0,0 +1 @@ +module github.com/mattn/go-shellwords diff --git a/vendor/github.com/mattn/go-shellwords/shellwords.go b/vendor/github.com/mattn/go-shellwords/shellwords.go index bcd1e1f06ec..41429d8f26f 100644 --- a/vendor/github.com/mattn/go-shellwords/shellwords.go +++ b/vendor/github.com/mattn/go-shellwords/shellwords.go @@ -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) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 4f0c80bcf85..0076218469d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -588,7 +588,7 @@ github.com/mailru/easyjson/jlexer github.com/mailru/easyjson/jwriter # github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c => github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c github.com/marstr/guid -# github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de => github.com/mattn/go-shellwords v0.0.0-20180605041737-f8471b0a71de +# github.com/mattn/go-shellwords v1.0.5 => github.com/mattn/go-shellwords v1.0.5 github.com/mattn/go-shellwords # github.com/matttproud/golang_protobuf_extensions v1.0.1 => github.com/matttproud/golang_protobuf_extensions v1.0.1 github.com/matttproud/golang_protobuf_extensions/pbutil