From 3d6d9061e3df82bd1728de9873b872e2800c3b92 Mon Sep 17 00:00:00 2001 From: Manjunath A Kumatagi Date: Tue, 11 Apr 2017 18:14:00 +0530 Subject: [PATCH] Vendor package update github.com/mattn/go-shellwords Signed-off-by: Manjunath A Kumatagi --- vendor.conf | 2 +- vendor/github.com/mattn/go-shellwords/LICENSE | 21 ++++++++++++++++ .../github.com/mattn/go-shellwords/README.md | 2 +- .../mattn/go-shellwords/shellwords.go | 25 +++++++++++++------ 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 vendor/github.com/mattn/go-shellwords/LICENSE diff --git a/vendor.conf b/vendor.conf index ea4ac6d9e5..e2aa557a14 100644 --- a/vendor.conf +++ b/vendor.conf @@ -10,7 +10,7 @@ github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://githu github.com/gorilla/context v1.1 github.com/gorilla/mux v1.1 github.com/kr/pty 5cf931ef8f -github.com/mattn/go-shellwords v1.0.0 +github.com/mattn/go-shellwords v1.0.3 github.com/tchap/go-patricia v2.2.6 github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3 # forked golang.org/x/net package includes a patch for lazy loading trace templates diff --git a/vendor/github.com/mattn/go-shellwords/LICENSE b/vendor/github.com/mattn/go-shellwords/LICENSE new file mode 100644 index 0000000000..740fa93132 --- /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 56f357fad7..b1d235c78d 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/shellwords.go b/vendor/github.com/mattn/go-shellwords/shellwords.go index 1abaa6c9df..107803927a 100644 --- a/vendor/github.com/mattn/go-shellwords/shellwords.go +++ b/vendor/github.com/mattn/go-shellwords/shellwords.go @@ -4,7 +4,6 @@ import ( "errors" "os" "regexp" - "strings" ) var ( @@ -35,21 +34,24 @@ func replaceEnv(s string) string { type Parser struct { ParseEnv bool ParseBacktick bool + Position int } func NewParser() *Parser { - return &Parser{ParseEnv, ParseBacktick} + return &Parser{ParseEnv, ParseBacktick, 0} } func (p *Parser) Parse(line string) ([]string, error) { - line = strings.TrimSpace(line) - args := []string{} buf := "" var escaped, doubleQuoted, singleQuoted, backQuote bool backtick := "" - for _, r := range line { + pos := -1 + got := false + +loop: + for i, r := range line { if escaped { buf += string(r) escaped = false @@ -69,12 +71,13 @@ func (p *Parser) Parse(line string) ([]string, error) { if singleQuoted || doubleQuoted || backQuote { buf += string(r) backtick += string(r) - } else if buf != "" { + } else if got { if p.ParseEnv { buf = replaceEnv(buf) } args = append(args, buf) buf = "" + got = false } continue } @@ -107,15 +110,21 @@ func (p *Parser) Parse(line string) ([]string, error) { singleQuoted = !singleQuoted continue } + case ';', '&', '|', '<', '>': + if !(escaped || singleQuoted || doubleQuoted || backQuote) { + pos = i + break loop + } } + got = true buf += string(r) if backQuote { backtick += string(r) } } - if buf != "" { + if got { if p.ParseEnv { buf = replaceEnv(buf) } @@ -126,6 +135,8 @@ func (p *Parser) Parse(line string) ([]string, error) { return nil, errors.New("invalid command line string") } + p.Position = pos + return args, nil }