Repository: caarlos0/env (go)

Issue:
Bug: fails to parse into fields with value
A regression was introduced in v7. When we pass a struct with non-nil pointer fields, `Parse` fails.

```go
func TestIssue(t *testing.T) {
	t.Run("Should parse with bool ptr set and env undefined", func(t *testing.T) {
		existingValue := true
		cfg := Config{
			BoolPtr: &existingValue,
		}

		isNoErr(t, Parse(&cfg))

		isEqual(t, &existingValue, cfg.BoolPtr)
	})

	t.Run("Should parse with bool ptr set and env defined", func(t *testing.T) {
		existingValue := true
		cfg := Config{
			BoolPtr: &existingValue,
		}

		newValue := false
		t.Setenv("BOOL", strconv.FormatBool(newValue))

		isNoErr(t, Parse(&cfg))

		isEqual(t, &newValue, cfg.BoolPtr)
	})
}
```

In 850c2d8 - this test passes.

In b135bbd and up to the current main - this test fails.

```
=== RUN   TestIssue/Should_parse_with_bool_ptr_set_and_env_undefined
    env_test.go:2199: unexpected error: env: expected a pointer to a Struct
```

Pull request:
Fix issue parsing into ptr fields with value
Closes #339

Patch:
diff --git a/env.go b/env.go
index d24c32e..b815e79 100644
--- a/env.go
+++ b/env.go
@@ -355,7 +355,7 @@ func doParseField(
 	if !refField.CanSet() {
 		return nil
 	}
-	if reflect.Ptr == refField.Kind() && !refField.IsNil() {
+	if reflect.Ptr == refField.Kind() && refField.Elem().Kind() == reflect.Struct && !refField.IsNil() {
 		return parseInternal(refField.Interface(), processField, optionsWithEnvPrefix(refTypeField, opts))
 	}
 	if reflect.Struct == refField.Kind() && refField.CanAddr() && refField.Type().Name() == "" {


Test patch:
diff --git a/env_test.go b/env_test.go
index 3ccaae4..6017889 100644
--- a/env_test.go
+++ b/env_test.go
@@ -2254,3 +2254,55 @@ func TestNoEnvKeyIgnored(t *testing.T) {
 	isEqual(t, "", cfg.Foo)
 	isEqual(t, "202", cfg.FooBar)
 }
+
+func TestIssue339(t *testing.T) {
+	t.Run("Should parse with bool ptr set and env undefined", func(t *testing.T) {
+		existingValue := true
+		cfg := Config{
+			BoolPtr: &existingValue,
+		}
+
+		isNoErr(t, Parse(&cfg))
+
+		isEqual(t, &existingValue, cfg.BoolPtr)
+	})
+
+	t.Run("Should parse with bool ptr set and env defined", func(t *testing.T) {
+		existingValue := true
+		cfg := Config{
+			BoolPtr: &existingValue,
+		}
+
+		newValue := false
+		t.Setenv("BOOL", strconv.FormatBool(newValue))
+
+		isNoErr(t, Parse(&cfg))
+
+		isEqual(t, &newValue, cfg.BoolPtr)
+	})
+
+	t.Run("Should parse with string ptr set and env undefined", func(t *testing.T) {
+		existingValue := "one"
+		cfg := Config{
+			StringPtr: &existingValue,
+		}
+
+		isNoErr(t, Parse(&cfg))
+
+		isEqual(t, &existingValue, cfg.StringPtr)
+	})
+
+	t.Run("Should parse with string ptr set and env defined", func(t *testing.T) {
+		existingValue := "one"
+		cfg := Config{
+			StringPtr: &existingValue,
+		}
+
+		newValue := "two"
+		t.Setenv("STRING", newValue)
+
+		isNoErr(t, Parse(&cfg))
+
+		isEqual(t, &newValue, cfg.StringPtr)
+	})
+}