From fce24f5ad3ee5921a72a599f0b1a39cdc8d98198 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Fri, 22 Feb 2019 16:54:29 +0000 Subject: [PATCH] vendor: github.com/mattn/go-shellwords@v1.0.4 --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/mattn/go-shellwords/LICENSE | 21 +++++ .../github.com/mattn/go-shellwords/README.md | 2 +- vendor/github.com/mattn/go-shellwords/go.mod | 1 + .../mattn/go-shellwords/shellwords.go | 76 +++++++++++++++---- .../mattn/go-shellwords/util_go15.go | 24 ++++++ .../mattn/go-shellwords/util_posix.go | 5 +- .../mattn/go-shellwords/util_windows.go | 5 ++ vendor/modules.txt | 2 +- 10 files changed, 122 insertions(+), 20 deletions(-) create mode 100644 vendor/github.com/mattn/go-shellwords/LICENSE create mode 100644 vendor/github.com/mattn/go-shellwords/go.mod create mode 100644 vendor/github.com/mattn/go-shellwords/util_go15.go diff --git a/go.mod b/go.mod index ddba18147..cd952015c 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/masterzen/simplexml v0.0.0-20160608183007-4572e39b1ab9 // indirect github.com/masterzen/winrm v0.0.0-20180224160350-7e40f93ae939 github.com/mattn/go-colorable v0.1.1 - github.com/mattn/go-shellwords v1.0.1 + github.com/mattn/go-shellwords v1.0.4 github.com/miekg/dns v1.0.8 // indirect github.com/mitchellh/cli v1.0.0 github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db diff --git a/go.sum b/go.sum index 5a258e897..93b344152 100644 --- a/go.sum +++ b/go.sum @@ -259,8 +259,8 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-shellwords v1.0.1 h1:2/mQs/EosKUge1MHnAavnrNwa0wLnWDjG4dTYMGf/kI= -github.com/mattn/go-shellwords v1.0.1/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= +github.com/mattn/go-shellwords v1.0.4 h1:xmZZyxuP+bYKAKkA9ABYXVNJ+G/Wf3R8d8vAP3LDJJk= +github.com/mattn/go-shellwords v1.0.4/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/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= diff --git a/vendor/github.com/mattn/go-shellwords/LICENSE b/vendor/github.com/mattn/go-shellwords/LICENSE new file mode 100644 index 000000000..740fa9313 --- /dev/null +++ b/vendor/github.com/mattn/go-shellwords/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Yasuhiro Matsumoto + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/mattn/go-shellwords/README.md b/vendor/github.com/mattn/go-shellwords/README.md index 56f357fad..b1d235c78 100644 --- a/vendor/github.com/mattn/go-shellwords/README.md +++ b/vendor/github.com/mattn/go-shellwords/README.md @@ -40,7 +40,7 @@ This is based on cpan module [Parse::CommandLine](https://metacpan.org/pod/Parse # License -under the MIT License: http://mattn.mit-license.org/2014 +under the MIT License: http://mattn.mit-license.org/2017 # Author 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 000000000..8d96dbd5f --- /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 355bdae68..f93e264c5 100644 --- a/vendor/github.com/mattn/go-shellwords/shellwords.go +++ b/vendor/github.com/mattn/go-shellwords/shellwords.go @@ -21,13 +21,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,19 +39,28 @@ 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) { args := []string{} buf := "" - var escaped, doubleQuoted, singleQuoted, backQuote bool + var escaped, doubleQuoted, singleQuoted, backQuote, dollarQuote bool backtick := "" pos := -1 + got := false loop: for i, r := range line { @@ -67,22 +80,23 @@ loop: } if isSpace(r) { - if singleQuoted || doubleQuoted || backQuote { + if singleQuoted || doubleQuoted || backQuote || dollarQuote { buf += string(r) backtick += string(r) - } else if buf != "" { + } else if got { if p.ParseEnv { - buf = replaceEnv(buf) + buf = replaceEnv(p.Getenv, buf) } args = append(args, buf) buf = "" + got = false } continue } switch r { case '`': - if !singleQuoted && !doubleQuoted { + if !singleQuoted && !doubleQuoted && !dollarQuote { if p.ParseBacktick { if backQuote { out, err := shellRun(backtick) @@ -98,37 +112,71 @@ loop: backtick = "" backQuote = !backQuote } + case ')': + if !singleQuoted && !doubleQuoted && !backQuote { + if p.ParseBacktick { + if dollarQuote { + out, err := shellRun(backtick) + if err != nil { + return nil, err + } + buf = out + } + backtick = "" + dollarQuote = !dollarQuote + continue + } + backtick = "" + dollarQuote = !dollarQuote + } + case '(': + if !singleQuoted && !doubleQuoted && !backQuote { + if !dollarQuote && len(buf) > 0 && buf == "$" { + dollarQuote = true + buf += "(" + continue + } else { + return nil, errors.New("invalid command line string") + } + } case '"': - if !singleQuoted { + if !singleQuoted && !dollarQuote { doubleQuoted = !doubleQuoted continue } case '\'': - if !doubleQuoted { + if !doubleQuoted && !dollarQuote { singleQuoted = !singleQuoted continue } case ';', '&', '|', '<', '>': if !(escaped || singleQuoted || doubleQuoted || backQuote) { + if r == '>' && len(buf) > 0 { + if c := buf[0]; '0' <= c && c <= '9' { + i -= 1 + got = false + } + } pos = i break loop } } + got = true buf += string(r) - if backQuote { + if backQuote || dollarQuote { backtick += string(r) } } - if buf != "" { + if got { if p.ParseEnv { - buf = replaceEnv(buf) + buf = replaceEnv(p.Getenv, buf) } args = append(args, buf) } - if escaped || singleQuoted || doubleQuoted || backQuote { + if escaped || singleQuoted || doubleQuoted || backQuote || dollarQuote { return nil, errors.New("invalid command line string") } diff --git a/vendor/github.com/mattn/go-shellwords/util_go15.go b/vendor/github.com/mattn/go-shellwords/util_go15.go new file mode 100644 index 000000000..180f00f0b --- /dev/null +++ b/vendor/github.com/mattn/go-shellwords/util_go15.go @@ -0,0 +1,24 @@ +// +build !go1.6 + +package shellwords + +import ( + "os" + "os/exec" + "runtime" + "strings" +) + +func shellRun(line string) (string, error) { + var b []byte + var err error + if runtime.GOOS == "windows" { + b, err = exec.Command(os.Getenv("COMSPEC"), "/c", line).Output() + } else { + b, err = exec.Command(os.Getenv("SHELL"), "-c", line).Output() + } + if err != nil { + return "", err + } + return strings.TrimSpace(string(b)), nil +} diff --git a/vendor/github.com/mattn/go-shellwords/util_posix.go b/vendor/github.com/mattn/go-shellwords/util_posix.go index 4f8ac55e4..eaf1011d6 100644 --- a/vendor/github.com/mattn/go-shellwords/util_posix.go +++ b/vendor/github.com/mattn/go-shellwords/util_posix.go @@ -1,4 +1,4 @@ -// +build !windows +// +build !windows,go1.6 package shellwords @@ -13,6 +13,9 @@ func shellRun(line string) (string, error) { shell := os.Getenv("SHELL") b, err := exec.Command(shell, "-c", line).Output() if err != nil { + if eerr, ok := err.(*exec.ExitError); ok { + b = eerr.Stderr + } return "", errors.New(err.Error() + ":" + string(b)) } return strings.TrimSpace(string(b)), nil diff --git a/vendor/github.com/mattn/go-shellwords/util_windows.go b/vendor/github.com/mattn/go-shellwords/util_windows.go index 7cad4cf06..e46f89a1f 100644 --- a/vendor/github.com/mattn/go-shellwords/util_windows.go +++ b/vendor/github.com/mattn/go-shellwords/util_windows.go @@ -1,3 +1,5 @@ +// +build windows,go1.6 + package shellwords import ( @@ -11,6 +13,9 @@ func shellRun(line string) (string, error) { shell := os.Getenv("COMSPEC") b, err := exec.Command(shell, "/c", line).Output() if err != nil { + if eerr, ok := err.(*exec.ExitError); ok { + b = eerr.Stderr + } return "", errors.New(err.Error() + ":" + string(b)) } return strings.TrimSpace(string(b)), nil diff --git a/vendor/modules.txt b/vendor/modules.txt index 5e0646a6f..edb1b8c6b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -372,7 +372,7 @@ github.com/masterzen/winrm/soap github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.5 github.com/mattn/go-isatty -# github.com/mattn/go-shellwords v1.0.1 +# github.com/mattn/go-shellwords v1.0.4 github.com/mattn/go-shellwords # github.com/mitchellh/cli v1.0.0 github.com/mitchellh/cli