update github.com/compose-spec/compose-go to v1.0.8

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2022-01-06 11:41:45 +01:00
parent fe9f9bba87
commit f04c8c8430
12 changed files with 124 additions and 80 deletions

View File

@ -266,12 +266,12 @@ func parseLineWithLookup(line string, envMap map[string]string, lookupFn LookupF
firstColon := strings.Index(line, ":")
splitString := strings.SplitN(line, "=", 2)
if firstColon != -1 && (firstColon < firstEquals || firstEquals == -1) {
//this is a yaml-style line
// This is a yaml-style line
splitString = strings.SplitN(line, ":", 2)
}
if len(splitString) != 2 {
err = errors.New("Can't separate key from value")
err = errors.New("can't separate key from value")
return
}
key = exportRegex.ReplaceAllString(splitString[0], "$1")
@ -341,15 +341,15 @@ func expandVariables(v string, envMap map[string]string, lookupFn LookupFn) stri
if submatch[1] == "\\" || submatch[2] == "(" {
return submatch[0][1:]
} else if submatch[4] != "" {
//first check if we have defined this already earlier
// first check if we have defined this already earlier
if envMap[submatch[4]] != "" {
return envMap[submatch[4]]
}
if lookupFn == nil {
return ""
}
//if we have not defined it, check the lookup function provided
//by the user
// if we have not defined it, check the lookup function provided
// by the user
s2, ok := lookupFn(submatch[4])
if ok {
return s2

View File

@ -127,15 +127,21 @@ loop:
// extractVarValue extracts variable value and returns rest of slice
func extractVarValue(src []byte, envMap map[string]string, lookupFn LookupFn) (value string, rest []byte, err error) {
quote, hasPrefix := hasQuotePrefix(src)
if !hasPrefix {
// unquoted value - read until whitespace
end := bytes.IndexFunc(src, unicode.IsSpace)
if end == -1 {
return expandVariables(string(src), envMap, lookupFn), nil, nil
quote, isQuoted := hasQuotePrefix(src)
if !isQuoted {
// unquoted value - read until new line
end := bytes.IndexFunc(src, isNewLine)
var rest []byte
var value string
if end < 0 {
value := strings.TrimRightFunc(string(src), unicode.IsSpace)
rest = nil
return expandVariables(value, envMap, lookupFn), rest, nil
}
return expandVariables(string(src[0:end]), envMap, lookupFn), src[end:], nil
value = strings.TrimRightFunc(string(src[0:end]), unicode.IsSpace)
rest = src[end:]
return expandVariables(value, envMap, lookupFn), rest, nil
}
// lookup quoted string terminator
@ -192,7 +198,7 @@ func indexOfNonSpaceChar(src []byte) int {
}
// hasQuotePrefix reports whether charset starts with single or double quote and returns quote character
func hasQuotePrefix(src []byte) (prefix byte, isQuored bool) {
func hasQuotePrefix(src []byte) (quote byte, isQuoted bool) {
if len(src) == 0 {
return 0, false
}
@ -221,3 +227,9 @@ func isSpace(r rune) bool {
}
return false
}
// isNewLine reports whether the rune is a new line character
func isNewLine(r rune) bool {
return r == '\n'
}