-
Notifications
You must be signed in to change notification settings - Fork 61
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
Fixed render_header_value eternal loop if a value of nil is present #87
Conversation
In general this bug doesn't happen if rendering an entire message, since render_headers detects and drops nils. However if one should render a header directly using render_header it bypasses this reduction and ends up looping in render_header_value This happens since it falls back to the last overload of the function, which wraps the value into a list. Since render_header_value can't handle empty lists, it falls back again and wraps the empty list (producing the same list), and keeps looping. The change presented here will treat such cases as a critical failure and will crash. This is chosen instead of quietly ignoring the issue or casting the nil to a string "nil" to avoid hiding potential errors
Maybe I'm missing the obvious, but how is the guard any different than what is already there? The prior other implementation of that private function is expecting a list for the 2nd argument. So when it isn't a list shouldn't it defer to the 2nd implementation of the private function? The guard seems redundant in this case. Please explain 😄 |
What I mean by above: if you pass |
@bcardarella Indeed it will error out, and that is intended, the other options are:
As for the use of a guard: This will not affect normal rendering of messages, since Instead this change would affect anything calling As for a use case: My use case is actually for But that is a private function and instead of making it public I opted to use |
This is already in master: https://github.com/DockYard/elixir-mail/blob/master/lib/mail/renderers/rfc_2822.ex#L118 so this pull request can probably be closed. |
It's been quite some time since I opened this... @andrewtimberlake I know, because I patched that previously, that was a different issue, I don't remember the exact details. But this case is different: elixir-mail/lib/mail/renderers/rfc_2822.ex Lines 114 to 118 in 519cc0e
Go ahead and run any of the below lines in an iex terminal with mail loaded
They will never return. My patch aims to have it crash immediately if it encounters a list that wasn't handled by the previous function. So the below would happen instead:
|
@IceDragon200 I’m closing this because this issue is now resolved with a refactor done in #93 |
Found a terrible bug in prod.
I use
render_header
directly for some internal stuff, and found that if you pass nil in as the value, it loops foreverIt was a really bad evening...
Changes proposed in this pull request
A fix for an eternal loop in render_header_value