mirror of https://github.com/joho/godotenv.git
sort output of Write/Marshal
parent
9f04f40640
commit
3dd2dbe832
|
@ -21,6 +21,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -165,6 +166,7 @@ func Marshal(envMap map[string]string) (string, error) {
|
|||
for k, v := range envMap {
|
||||
lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))
|
||||
}
|
||||
sort.Strings(lines)
|
||||
return strings.Join(lines, "\n"), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -348,6 +348,9 @@ func TestWrite(t *testing.T) {
|
|||
writeAndCompare(`key=va'lu'e`, `key="va'lu'e"`)
|
||||
// newlines, backslashes, and some other special chars are escaped
|
||||
writeAndCompare(`foo="$ba\n\r\\r!"`, `foo="\$ba\n\r\\r\!"`)
|
||||
// lines should be sorted
|
||||
writeAndCompare("foo=bar\nbaz=buzz", "baz=\"buzz\"\nfoo=\"bar\"")
|
||||
|
||||
}
|
||||
|
||||
func TestRoundtrip(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue