feat: add StringToMailAddressHookFunc#109
feat: add StringToMailAddressHookFunc#109KianYang-Lee wants to merge 5 commits intogo-viper:mainfrom
Conversation
sagikazarmark
left a comment
There was a problem hiding this comment.
Could you please rebase your PR and add some tests?
Thanks!
12f7f91 to
d279398
Compare
Done |
sagikazarmark
left a comment
There was a problem hiding this comment.
Apologies for a second round, but I had another finding. PTAL, thanks!
| // Convert it by parsing | ||
| addr, err := mail.ParseAddress(data.(string)) | ||
| if err != nil { | ||
| return mail.Address{}, fmt.Errorf("failed parsing mail address %v: %w", data, err) |
There was a problem hiding this comment.
As of 2.4.0 decode hooks must not return errors that have the decoded value in the error message.
Please take a look at other decode hooks (particularly net and time hooks) for examples.
Also, I briefly looked into the mail package and it looks like in some cases their error messages also contain the decoded value. That needs to be dealt with as well.
Make sure to add a test here as well verifying that the decode hook doesn't leak values: https://github.com/go-viper/mapstructure/blob/main/decode_hooks_test.go#L2055
Add a new
StringToMailAddressHookFuncto convert strings tomail.Address.Closes #108