forked from coop-cloud-mirrors/godotenv
commit
3e4069b9b2
@ -22,6 +22,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -169,7 +170,11 @@ func Write(envMap map[string]string, filename string) error {
|
|||||||
func Marshal(envMap map[string]string) (string, error) {
|
func Marshal(envMap map[string]string) (string, error) {
|
||||||
lines := make([]string, 0, len(envMap))
|
lines := make([]string, 0, len(envMap))
|
||||||
for k, v := range envMap {
|
for k, v := range envMap {
|
||||||
lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))
|
if d, err := strconv.Atoi(v); err == nil {
|
||||||
|
lines = append(lines, fmt.Sprintf(`%s=%d`, k, d))
|
||||||
|
} else {
|
||||||
|
lines = append(lines, fmt.Sprintf(`%s="%s"`, k, doubleQuoteEscape(v)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sort.Strings(lines)
|
sort.Strings(lines)
|
||||||
return strings.Join(lines, "\n"), nil
|
return strings.Join(lines, "\n"), nil
|
||||||
|
@ -445,6 +445,8 @@ func TestWrite(t *testing.T) {
|
|||||||
writeAndCompare(`foo="\n\r\\r!"`, `foo="\n\r\\r\!"`)
|
writeAndCompare(`foo="\n\r\\r!"`, `foo="\n\r\\r\!"`)
|
||||||
// lines should be sorted
|
// lines should be sorted
|
||||||
writeAndCompare("foo=bar\nbaz=buzz", "baz=\"buzz\"\nfoo=\"bar\"")
|
writeAndCompare("foo=bar\nbaz=buzz", "baz=\"buzz\"\nfoo=\"bar\"")
|
||||||
|
// integers should not be quoted
|
||||||
|
writeAndCompare(`key="10"`, `key=10`)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user