bump mattn/go-shellwords v1.0.6

full diff: https://github.com/mattn/go-shellwords/compare/v1.0.5...v1.0.6

relevant changes:

- mattn/go-shellwords#24 Add dir option for parser
- mattn/go-shellwords#26 Fix backquote in part of argument
    - fixes mattn/go-shellwords#25 Backtick "eats" all runes until isSpace
- mattn/go-shellwords#28 Fix dollar quote
    - fixes mattn/go-shellwords#27 Multi-commands inside of command substitution are throwing "invalid command line string" errors
- mattn/go-shellwords#24 Add dir option for parser
- mattn/go-shellwords#24 Add dir option for parser
- mattn/go-shellwords#24 Add dir option for parser

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-10-23 15:19:20 +02:00
parent c07b1b275e
commit 6a26d370ad
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
6 changed files with 29 additions and 18 deletions

View File

@ -47,7 +47,7 @@ github.com/inconshreveable/mousetrap 76626ae9c91c4f2a10f34cad8ce8
github.com/jaguilar/vt100 ad4c4a5743050fb7f88ce968dca9422f72a0e3f2 git://github.com/tonistiigi/vt100.git
github.com/json-iterator/go 0ff49de124c6f76f8494e194af75bde0f1a49a29 # 1.1.6
github.com/konsorten/go-windows-terminal-sequences f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2
github.com/mattn/go-shellwords a72fbe27a1b0ed0df2f02754945044ce1456608b # v1.0.5
github.com/mattn/go-shellwords 36a9b3c57cb5caa559ff63fb7e9b585f1c00df75 # v1.0.6
github.com/matttproud/golang_protobuf_extensions c12348ce28de40eed0136aa2b644d0ee0650e56c # v1.0.1
github.com/Microsoft/go-winio 6c72808b55902eae4c5943626030429ff20f3b63 # v0.4.14
github.com/Microsoft/hcsshim 672e52e9209d1e53718c1b6a7d68cc9272654ab5

View File

@ -1,6 +1,6 @@
# go-shellwords
[![Coverage Status](https://coveralls.io/repos/mattn/go-shellwords/badge.png?branch=master)](https://coveralls.io/r/mattn/go-shellwords?branch=master)
[![codecov](https://codecov.io/gh/mattn/go-shellwords/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-shellwords)
[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords)
Parse line as shell words.

View File

@ -40,6 +40,7 @@ type Parser struct {
ParseEnv bool
ParseBacktick bool
Position int
Dir string
// If ParseEnv is true, use this for getenv.
// If nil, use os.Getenv.
@ -51,6 +52,7 @@ func NewParser() *Parser {
ParseEnv: ParseEnv,
ParseBacktick: ParseBacktick,
Position: 0,
Dir: "",
}
}
@ -100,11 +102,11 @@ loop:
if !singleQuoted && !doubleQuoted && !dollarQuote {
if p.ParseBacktick {
if backQuote {
out, err := shellRun(backtick)
out, err := shellRun(backtick, p.Dir)
if err != nil {
return nil, err
}
buf = out
buf = buf[:len(buf)-len(backtick)] + out
}
backtick = ""
backQuote = !backQuote
@ -117,15 +119,11 @@ loop:
if !singleQuoted && !doubleQuoted && !backQuote {
if p.ParseBacktick {
if dollarQuote {
out, err := shellRun(backtick)
out, err := shellRun(backtick, p.Dir)
if err != nil {
return nil, err
}
if r == ')' {
buf = buf[:len(buf)-len(backtick)-2] + out
} else {
buf = buf[:len(buf)-len(backtick)-1] + out
}
}
backtick = ""
dollarQuote = !dollarQuote
@ -155,7 +153,7 @@ loop:
continue
}
case ';', '&', '|', '<', '>':
if !(escaped || singleQuoted || doubleQuoted || backQuote) {
if !(escaped || singleQuoted || doubleQuoted || backQuote || dollarQuote) {
if r == '>' && len(buf) > 0 {
if c := buf[0]; '0' <= c && c <= '9' {
i -= 1

View File

@ -9,14 +9,19 @@ import (
"strings"
)
func shellRun(line string) (string, error) {
func shellRun(line, dir string) (string, error) {
var b []byte
var err error
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
b, err = exec.Command(os.Getenv("COMSPEC"), "/c", line).Output()
cmd = exec.Command(os.Getenv("COMSPEC"), "/c", line)
} else {
b, err = exec.Command(os.Getenv("SHELL"), "-c", line).Output()
cmd = exec.Command(os.Getenv("SHELL"), "-c", line)
}
if dir != "" {
cmd.Dir = dir
}
b, err = cmd.Output()
if err != nil {
return "", err
}

View File

@ -9,9 +9,13 @@ import (
"strings"
)
func shellRun(line string) (string, error) {
func shellRun(line, dir string) (string, error) {
shell := os.Getenv("SHELL")
b, err := exec.Command(shell, "-c", line).Output()
cmd := exec.Command(shell, "-c", line)
if dir != "" {
cmd.Dir = dir
}
b, err := cmd.Output()
if err != nil {
if eerr, ok := err.(*exec.ExitError); ok {
b = eerr.Stderr

View File

@ -9,9 +9,13 @@ import (
"strings"
)
func shellRun(line string) (string, error) {
func shellRun(line, dir string) (string, error) {
shell := os.Getenv("COMSPEC")
b, err := exec.Command(shell, "/c", line).Output()
cmd := exec.Command(shell, "/c", line)
if dir != "" {
cmd.Dir = dir
}
b, err := cmd.Output()
if err != nil {
if eerr, ok := err.(*exec.ExitError); ok {
b = eerr.Stderr