Skip to content

Commit

Permalink
fix: Properly handle null header values (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
drish authored Jan 8, 2025
1 parent 08befa6 commit fdcca66
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
resend (0.16.0)
resend (0.17.1)
httparty (>= 0.21.0)

GEM
Expand Down
2 changes: 2 additions & 0 deletions lib/resend/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def headers_values(mail)
unignored_headers(mail).each do |h|
params[h.name.to_s] = h.unparsed_value
end
# remove nil header values
params.delete_if { |_k, v| v.nil? }
params
end

Expand Down
2 changes: 1 addition & 1 deletion lib/resend/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Resend
VERSION = "0.17.0"
VERSION = "0.17.1"
end
16 changes: 15 additions & 1 deletion spec/railtie/mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def with_overwritten_headers(to, subject)
end
end

def with_nil_header_values(to, subject)
headers["X-Entity-Ref-ID"] = nil
mail(to: to, subject: subject) do |format|
format.text { render plain: "txt" }
format.html { render html: "<p>html</p>".html_safe }
end
end

def with_attachment(to, subject)
attachments['invoice.pdf'] = {
:content => File.read('resources/invoice.pdf'),
Expand Down Expand Up @@ -135,7 +143,7 @@ class TestMailerWithDisplayName < TestMailer
expect(body[:headers]["X-Entity-Ref-ID"]).to eql("123")
end

it "#mail properly overwrites #headers" do
it "#build_resend_params properly overwrites #headers" do
message = TestMailer.with_overwritten_headers("[email protected]", "Test!")
body = @mailer.build_resend_params(message)
expect(body[:from]).to eql("[email protected]")
Expand All @@ -145,4 +153,10 @@ class TestMailerWithDisplayName < TestMailer
expect(body[:text]).to eql("txt")
expect(body[:headers]["X-Entity-Ref-ID"]).to eql("overwritten")
end

it "#build_resend_params handles nil values" do
message = TestMailer.with_nil_header_values("[email protected]", "Test!")
body = @mailer.build_resend_params(message)
expect(body[:headers]).to be nil
end
end

0 comments on commit fdcca66

Please sign in to comment.