@@ -17,7 +17,6 @@ import (
1717 "errors"
1818 "fmt"
1919 "io"
20- "io/ioutil"
2120 "os"
2221 "os/exec"
2322 "regexp"
@@ -44,7 +43,7 @@ func Parse(r io.Reader) (map[string]string, error) {
4443
4544// ParseWithLookup reads an env file from io.Reader, returning a map of keys and values.
4645func ParseWithLookup (r io.Reader , lookupFn LookupFn ) (map [string ]string , error ) {
47- data , err := ioutil .ReadAll (r )
46+ data , err := io .ReadAll (r )
4847 if err != nil {
4948 return nil , err
5049 }
@@ -184,7 +183,7 @@ func Marshal(envMap map[string]string) (string, error) {
184183 if d , err := strconv .Atoi (v ); err == nil {
185184 lines = append (lines , fmt .Sprintf (`%s=%d` , k , d ))
186185 } else {
187- lines = append (lines , fmt .Sprintf (`%s="%s"` , k , doubleQuoteEscape (v )))
186+ lines = append (lines , fmt .Sprintf (`%s="%s"` , k , doubleQuoteEscape (v ))) //nolint // Cannot use %q here
188187 }
189188 }
190189 sort .Strings (lines )
@@ -235,10 +234,9 @@ var exportRegex = regexp.MustCompile(`^\s*(?:export\s+)?(.*?)\s*$`)
235234func parseLine (line string , envMap map [string ]string ) (key string , value string , err error ) {
236235 return parseLineWithLookup (line , envMap , nil )
237236}
238- func parseLineWithLookup (line string , envMap map [string ]string , lookupFn LookupFn ) (key string , value string , err error ) {
239- if len (line ) == 0 {
240- err = errors .New ("zero length string" )
241- return
237+ func parseLineWithLookup (line string , envMap map [string ]string , lookupFn LookupFn ) (string , string , error ) {
238+ if line == "" {
239+ return "" , "" , errors .New ("zero length string" )
242240 }
243241
244242 // ditch the comments (but keep quoted hashes)
@@ -271,14 +269,14 @@ func parseLineWithLookup(line string, envMap map[string]string, lookupFn LookupF
271269 }
272270
273271 if len (splitString ) != 2 {
274- err = errors .New ("can't separate key from value" )
275- return
272+ return "" , "" , errors .New ("can't separate key from value" )
276273 }
277- key = exportRegex .ReplaceAllString (splitString [0 ], "$1" )
274+ key : = exportRegex .ReplaceAllString (splitString [0 ], "$1" )
278275
279276 // Parse the value
280- value = parseValue (splitString [1 ], envMap , lookupFn )
281- return
277+ value := parseValue (splitString [1 ], envMap , lookupFn )
278+
279+ return key , value , nil
282280}
283281
284282var (
@@ -351,7 +349,7 @@ func doubleQuoteEscape(line string) string {
351349 if c == '\r' {
352350 toReplace = `\r`
353351 }
354- line = strings .Replace (line , string (c ), toReplace , - 1 )
352+ line = strings .ReplaceAll (line , string (c ), toReplace )
355353 }
356354 return line
357355}
0 commit comments