-
Notifications
You must be signed in to change notification settings - Fork 37
feat: add StringToMailAddressHookFunc #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: add StringToMailAddressHookFunc #109
Conversation
sagikazarmark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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