Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compatibility issue with Mail 2.7.0
In Mail 2.7.0 in an actual Rails application, HTML part of the body now returns an `ActiveSupport::SafeBuffer` object instead of a String object. This causes a problem as there is a known issue of how `SafeBuffer#gsub` with a block form is broken in Rails[1], and that `HTMLEntities#decode` actually performs a `gsub` with a block internally[2]. Upon further investigation, however, it seems like the root cause of this issue might not be on Mail gem, but actually on `ERB::Util.h` returning `ActiveSupport::SafeBuffer` object instead of `String`[3]. This commit changes `default_part_body` method to call `to_s.to_str` on the message body so that we'll be able to pass a String object, which always works with `gsub`, to `HTMLEntities#decode`. Please note that we need to call `to_s.to_str` on the object because `ActiveSupport::SafeBuffer` actually overrides `to_s` to return itself and not the underlying `String` object. I believe this PR should fix issue #202, #204, and #205, and it's better to fix the issue here than in `HTMLEntities`. [1]: rails/rails#1555 [2]: https://github.com/threedaymonk/htmlentities/blob/v4.3.3/lib/htmlentities/decoder.rb#L10-L20 [3]: threedaymonk/htmlentities#33 (comment)
- Loading branch information