From 9e39481dda5560953033d1b7ba478e9cf76099d2 Mon Sep 17 00:00:00 2001 From: Kirill Mikhailets Date: Thu, 30 Mar 2023 15:03:40 +0200 Subject: [PATCH] Fix content-type checker --- lib/premailer/rails/hook.rb | 4 ++-- spec/integration/hook_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/premailer/rails/hook.rb b/lib/premailer/rails/hook.rb index 00dbae0..75327a6 100644 --- a/lib/premailer/rails/hook.rb +++ b/lib/premailer/rails/hook.rb @@ -42,7 +42,7 @@ def message_contains_html? # Returns true if the message itself has a content type of text/html, thus # it does not contain other parts such as alternatives and attachments. def pure_html_message? - message.content_type && message.content_type.include?('text/html') + message.content_type && message.content_type.start_with?('text/html') end def generate_html_part_replacement @@ -112,7 +112,7 @@ def replace_html_part(new_part) # If the new part is a pure text/html part, the body and its content type # are used for the message. If the new part is def replace_in_pure_html_message(new_part) - if new_part.content_type.include?('text/html') + if new_part.content_type.start_with?('text/html') message.body = new_part.decoded message.content_type = new_part.content_type else diff --git a/spec/integration/hook_spec.rb b/spec/integration/hook_spec.rb index d9c4080..97e8a21 100644 --- a/spec/integration/hook_spec.rb +++ b/spec/integration/hook_spec.rb @@ -144,6 +144,14 @@ def html_string include 'multipart/alternative' expect(processed_message.parts.last.content_type).to include 'image/png' end + + context 'with content-type "type" set' do + before { message.content_type += '; type="text/html"' } + + it 'does not change content-type' do + expect(processed_message.content_type).to include 'multipart/mixed' + end + end end context 'when message has a skip premailer header' do