@@ -127,15 +127,21 @@ loop:
127127
128128// extractVarValue extracts variable value and returns rest of slice
129129func extractVarValue (src []byte , envMap map [string ]string , lookupFn LookupFn ) (value string , rest []byte , err error ) {
130- quote , hasPrefix := hasQuotePrefix (src )
131- if ! hasPrefix {
132- // unquoted value - read until whitespace
133- end := bytes .IndexFunc (src , unicode .IsSpace )
134- if end == - 1 {
135- return expandVariables (string (src ), envMap , lookupFn ), nil , nil
130+ quote , isQuoted := hasQuotePrefix (src )
131+ if ! isQuoted {
132+ // unquoted value - read until new line
133+ end := bytes .IndexFunc (src , isNewLine )
134+ var rest []byte
135+ var value string
136+ if end < 0 {
137+ value := strings .TrimRightFunc (string (src ), unicode .IsSpace )
138+ rest = nil
139+ return expandVariables (value , envMap , lookupFn ), rest , nil
136140 }
137141
138- return expandVariables (string (src [0 :end ]), envMap , lookupFn ), src [end :], nil
142+ value = strings .TrimRightFunc (string (src [0 :end ]), unicode .IsSpace )
143+ rest = src [end :]
144+ return expandVariables (value , envMap , lookupFn ), rest , nil
139145 }
140146
141147 // lookup quoted string terminator
@@ -192,7 +198,7 @@ func indexOfNonSpaceChar(src []byte) int {
192198}
193199
194200// hasQuotePrefix reports whether charset starts with single or double quote and returns quote character
195- func hasQuotePrefix (src []byte ) (prefix byte , isQuored bool ) {
201+ func hasQuotePrefix (src []byte ) (quote byte , isQuoted bool ) {
196202 if len (src ) == 0 {
197203 return 0 , false
198204 }
@@ -221,3 +227,9 @@ func isSpace(r rune) bool {
221227 }
222228 return false
223229}
230+
231+
232+ // isNewLine reports whether the rune is a new line character
233+ func isNewLine (r rune ) bool {
234+ return r == '\n'
235+ }
0 commit comments