mirror of
https://github.com/golang/go
synced 2024-11-21 21:24:45 -07:00
Update exec_windows.go
change `hasSpace ` to `needsQuote` for better understanding
This commit is contained in:
parent
3930f1b536
commit
e20353eeba
@ -48,7 +48,7 @@ func appendEscapeArg(b []byte, s string) []byte {
|
||||
}
|
||||
|
||||
needsBackslash := false
|
||||
hasSpace := false
|
||||
needsQuote := false
|
||||
for i := 0; i < len(s); i++ {
|
||||
if !needsBackslash{
|
||||
switch s[i] {
|
||||
@ -56,26 +56,26 @@ func appendEscapeArg(b []byte, s string) []byte {
|
||||
needsBackslash = true
|
||||
}
|
||||
}
|
||||
if !hasSpace{
|
||||
if !needsQuote{
|
||||
switch s[i] {
|
||||
case ' ', '\t', '!','&', '(', ')', '[', ']', '{', '}', ';', '<', '>', '|':
|
||||
hasSpace = true
|
||||
needsQuote = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !needsBackslash && !hasSpace {
|
||||
if !needsBackslash && !needsQuote {
|
||||
// No special handling required; normal case.
|
||||
return append(b, s...)
|
||||
}
|
||||
if !needsBackslash {
|
||||
// hasSpace is true, so we need to quote the string.
|
||||
// needsQuote is true, so we need to quote the string.
|
||||
b = append(b, '"')
|
||||
b = append(b, s...)
|
||||
return append(b, '"')
|
||||
}
|
||||
|
||||
if hasSpace {
|
||||
if needsQuote {
|
||||
b = append(b, '"')
|
||||
}
|
||||
slashes := 0
|
||||
@ -94,7 +94,7 @@ func appendEscapeArg(b []byte, s string) []byte {
|
||||
}
|
||||
b = append(b, c)
|
||||
}
|
||||
if hasSpace {
|
||||
if needsQuote {
|
||||
for ; slashes > 0; slashes-- {
|
||||
b = append(b, '\\')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user