vendor/github.com/subosito/gotenv/gotenv.go
changeset 265 05c40b36d3b2
parent 260 445e01aede7e
--- a/vendor/github.com/subosito/gotenv/gotenv.go	Thu Sep 22 16:37:07 2022 +0200
+++ b/vendor/github.com/subosito/gotenv/gotenv.go	Sat Feb 04 12:58:35 2023 +0100
@@ -3,6 +3,7 @@
 
 import (
 	"bufio"
+	"bytes"
 	"fmt"
 	"io"
 	"os"
@@ -174,9 +175,36 @@
 	return file.Sync()
 }
 
+// splitLines is a valid SplitFunc for a bufio.Scanner. It will split lines on CR ('\r'), LF ('\n') or CRLF (any of the three sequences).
+// If a CR is immediately followed by a LF, it is treated as a CRLF (one single line break).
+func splitLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
+	if atEOF && len(data) == 0 {
+		return 0, nil, bufio.ErrFinalToken
+	}
+
+	idx := bytes.IndexAny(data, "\r\n")
+	switch {
+	case atEOF && idx < 0:
+		return len(data), data, bufio.ErrFinalToken
+
+	case idx < 0:
+		return 0, nil, nil
+	}
+
+	// consume CR or LF
+	eol := idx + 1
+	// detect CRLF
+	if len(data) > eol && data[eol-1] == '\r' && data[eol] == '\n' {
+		eol++
+	}
+
+	return eol, data[:idx], nil
+}
+
 func strictParse(r io.Reader, override bool) (Env, error) {
 	env := make(Env)
 	scanner := bufio.NewScanner(r)
+	scanner.Split(splitLines)
 
 	firstLine := true
 
@@ -283,7 +311,6 @@
 			return varReplacement(s, hsq, env, override)
 		}
 		val = varRgx.ReplaceAllStringFunc(val, fv)
-		val = parseVal(val, env, hdq, override)
 	}
 
 	env[key] = val
@@ -352,18 +379,3 @@
 
 	return fmt.Errorf("line `%s` doesn't match format", s)
 }
-
-func parseVal(val string, env Env, ignoreNewlines bool, override bool) string {
-	if strings.Contains(val, "=") && !ignoreNewlines {
-		kv := strings.Split(val, "\r")
-
-		if len(kv) > 1 {
-			val = kv[0]
-			for _, l := range kv[1:] {
-				_ = parseLine(l, env, override)
-			}
-		}
-	}
-
-	return val
-}