mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 01:39:06 +00:00
introduce one const value that indicate to no quote in ShlexSplit()
This commit is contained in:
@@ -18,8 +18,11 @@ func ShlexSplit(s string) ([]string, error) {
|
|||||||
func shlexSplit(s string) ([]string, error) {
|
func shlexSplit(s string) ([]string, error) {
|
||||||
result := []string{}
|
result := []string{}
|
||||||
|
|
||||||
|
// noQuote is used to track if we are not in a quoted
|
||||||
|
const noQuote = 0
|
||||||
|
|
||||||
var current strings.Builder
|
var current strings.Builder
|
||||||
var quote rune
|
var quote rune = noQuote
|
||||||
var escaped bool
|
var escaped bool
|
||||||
|
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
@@ -29,17 +32,17 @@ func shlexSplit(s string) ([]string, error) {
|
|||||||
escaped = false
|
escaped = false
|
||||||
case r == '\\' && quote != '\'':
|
case r == '\\' && quote != '\'':
|
||||||
escaped = true
|
escaped = true
|
||||||
case (r == '\'' || r == '"') && quote == 0:
|
case (r == '\'' || r == '"') && quote == noQuote:
|
||||||
quote = r
|
quote = r
|
||||||
case r == quote:
|
case r == quote:
|
||||||
quote = 0
|
quote = noQuote
|
||||||
case r == '#' && quote == 0:
|
case r == '#' && quote == noQuote:
|
||||||
// Comment starts, ignore the rest of the line
|
// Comment starts, ignore the rest of the line
|
||||||
if current.Len() > 0 {
|
if current.Len() > 0 {
|
||||||
result = append(result, current.String())
|
result = append(result, current.String())
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
case quote == 0 && unicode.IsSpace(r):
|
case unicode.IsSpace(r) && quote == noQuote:
|
||||||
if current.Len() > 0 {
|
if current.Len() > 0 {
|
||||||
result = append(result, current.String())
|
result = append(result, current.String())
|
||||||
current.Reset()
|
current.Reset()
|
||||||
@@ -49,7 +52,7 @@ func shlexSplit(s string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if quote != 0 {
|
if quote != noQuote {
|
||||||
return nil, fmt.Errorf("unclosed quote in string")
|
return nil, fmt.Errorf("unclosed quote in string")
|
||||||
}
|
}
|
||||||
if current.Len() > 0 {
|
if current.Len() > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user