diff --git a/vendor/modules.txt b/vendor/modules.txt index 866473f9..2dea7837 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -38,7 +38,7 @@ golang.org/x/sys/unix golang.org/x/sys/windows # gopkg.in/yaml.v2 v2.2.1 gopkg.in/yaml.v2 -# mvdan.cc/sh v2.6.3+incompatible +# mvdan.cc/sh v2.6.4-0.20190222161105-3c71c7be1070+incompatible mvdan.cc/sh/expand mvdan.cc/sh/interp mvdan.cc/sh/shell diff --git a/vendor/mvdan.cc/sh/expand/expand.go b/vendor/mvdan.cc/sh/expand/expand.go index 633b43a7..16f63d45 100644 --- a/vendor/mvdan.cc/sh/expand/expand.go +++ b/vendor/mvdan.cc/sh/expand/expand.go @@ -373,7 +373,11 @@ func (cfg *Config) wordField(wps []syntax.WordPart, ql quoteLevel) ([]fieldPart, case *syntax.Lit: s := x.Value if i == 0 && ql == quoteNone { - s = cfg.expandUser(s) + if prefix, rest := cfg.expandUser(s); prefix != "" { + // TODO: return two separate fieldParts, + // like in wordFields? + s = prefix + rest + } } if ql == quoteDouble && strings.Contains(s, "\\") { buf := cfg.strBuilder() @@ -468,7 +472,12 @@ func (cfg *Config) wordFields(wps []syntax.WordPart) ([][]fieldPart, error) { case *syntax.Lit: s := x.Value if i == 0 { - s = cfg.expandUser(s) + prefix, rest := cfg.expandUser(s) + curField = append(curField, fieldPart{ + quote: quoteSingle, + val: prefix, + }) + s = rest } if strings.Contains(s, "\\") { buf := cfg.strBuilder() @@ -562,28 +571,27 @@ func (cfg *Config) quotedElems(pe *syntax.ParamExp) []string { return nil } -func (cfg *Config) expandUser(field string) string { +func (cfg *Config) expandUser(field string) (prefix, rest string) { if len(field) == 0 || field[0] != '~' { - return field + return "", field } name := field[1:] - rest := "" if i := strings.Index(name, "/"); i >= 0 { rest = name[i:] name = name[:i] } if name == "" { - return cfg.Env.Get("HOME").String() + rest + return cfg.Env.Get("HOME").String(), rest } if vr := cfg.Env.Get("HOME " + name); vr.IsSet() { - return vr.String() + rest + return vr.String(), rest } u, err := user.Lookup(name) if err != nil { - return field + return "", field } - return u.HomeDir + rest + return u.HomeDir, rest } func findAllIndex(pattern, name string, n int) [][]int { diff --git a/vendor/mvdan.cc/sh/interp/interp.go b/vendor/mvdan.cc/sh/interp/interp.go index b7ce7657..4a5a8b41 100644 --- a/vendor/mvdan.cc/sh/interp/interp.go +++ b/vendor/mvdan.cc/sh/interp/interp.go @@ -1182,6 +1182,10 @@ func (r *Runner) findExecutable(file string, exts []string) string { return "" } +func driveLetter(c byte) bool { + return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') +} + // splitList is like filepath.SplitList, but always using the unix path // list separator ':'. On Windows, it also makes sure not to split // [A-Z]:[/\]. @@ -1198,8 +1202,7 @@ func splitList(path string) []string { for i := 0; i < len(list); i++ { s := list[i] switch { - case len(s) != 1, s[0] < 'A', s[0] > 'Z': - // not a disk name + case len(s) != 1, !driveLetter(s[0]): case i+1 >= len(list): // last element case strings.IndexAny(list[i+1], `/\`) != 0: diff --git a/vendor/mvdan.cc/sh/interp/test.go b/vendor/mvdan.cc/sh/interp/test.go index f5378433..96cc311b 100644 --- a/vendor/mvdan.cc/sh/interp/test.go +++ b/vendor/mvdan.cc/sh/interp/test.go @@ -19,7 +19,7 @@ import ( func (r *Runner) bashTest(ctx context.Context, expr syntax.TestExpr, classic bool) string { switch x := expr.(type) { case *syntax.Word: - return r.literal(x) + return r.document(x) case *syntax.ParenTest: return r.bashTest(ctx, x.X, classic) case *syntax.BinaryTest: diff --git a/vendor/mvdan.cc/sh/shell/doc.go b/vendor/mvdan.cc/sh/shell/doc.go index 695f233c..96ae5705 100644 --- a/vendor/mvdan.cc/sh/shell/doc.go +++ b/vendor/mvdan.cc/sh/shell/doc.go @@ -3,4 +3,12 @@ // Package shell contains high-level features that use the syntax, expand, and // interp packages under the hood. +// +// Please note that this package uses POSIX Shell syntax. As such, path names on +// Windows need to use double backslashes or be within single quotes when given +// to functions like Fields. For example: +// +// shell.Fields("echo /foo/bar") // on Unix-like +// shell.Fields("echo C:\\foo\\bar") // on Windows +// shell.Fields("echo 'C:\foo\bar'") // on Windows, with quotes package shell