diff --git a/godotenv.go b/godotenv.go index c560be5..54eebf4 100644 --- a/godotenv.go +++ b/godotenv.go @@ -160,10 +160,10 @@ func Write(envMap map[string]string, filename string) error { } func isInt(s string) bool { + s = strings.TrimPrefix(s, "-") + if len(s) == 0 { return false - } else if s[0] == '-' { - s = s[1:] } for _, r := range s { diff --git a/godotenv_test.go b/godotenv_test.go index f489615..c79912b 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -493,6 +493,8 @@ func TestIsInt(t *testing.T) { checkAndCompare("12a3", false) checkAndCompare("abc", false) checkAndCompare("12 3", false) + checkAndCompare("-", false) + checkAndCompare(" ", false) // valid values checkAndCompare("-123", true)