Skip to content

Commit

Permalink
fix '-' character trimming and expand the test
Browse files Browse the repository at this point in the history
  • Loading branch information
t3mp14r3 committed Sep 2, 2024
1 parent de05e2d commit 2f570db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions godotenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions godotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2f570db

Please sign in to comment.