Browse Source

Fixes #4184 - HTML comments/conditions being rendered from emails.

Florian Liebe 2 years ago
parent
commit
ec29f82893
2 changed files with 17 additions and 0 deletions
  1. 3 0
      lib/core_ext/string.rb
  2. 14 0
      spec/lib/core_ext/string_spec.rb

+ 3 - 0
lib/core_ext/string.rb

@@ -352,6 +352,9 @@ class String
     # https://github.com/zammad/zammad/issues/4112
     string.gsub!(%r{<!\[if !supportLists\]>.+?<!\[endif\]>}, '• ')
 
+    # https://github.com/zammad/zammad/issues/4184
+    string.gsub!(%r{<!\[if !\w+\]>(.+?)<!\[endif\]>}, '\1')
+
     string.signature_identify('html')
 
     marker_template = '<span class="js-signatureMarker"></span>'

+ 14 - 0
spec/lib/core_ext/string_spec.rb

@@ -1444,6 +1444,20 @@ RSpec.describe String do
           <p>• 1</p><p>• 2</p>
         TEXT
       end
+
+      # https://github.com/zammad/zammad/issues/4184
+      it 'deletes downlevel revealed conditional comments' do
+        expect(<<~HTML.chomp.html2html_strict).to eq(<<~TEXT.chomp)
+          <p class="MsoPlainText" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
+          <![if !vml]><img width="52" height="52" src="cid:image001.png@01D8AC0A.08251CD0" v:shapes="Picture_x0020_1"><![endif]>
+          <span style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black;mso-fareast-language:EN-AU">dummy1</span>
+          <![if !vml]><img width="52" height="52" src="cid:image002.png@01D8AC0A.08251CD1" v:shapes="Picture_x0020_2"><![endif]>
+          <span style="font-size:9.0pt;font-family:&quot;Arial&quot;,sans-serif;color:black;mso-fareast-language:EN-AU">dummy2</span>
+          </p>
+        HTML
+          <p> <img src="cid:image001.png@01D8AC0A.08251CD0" style="width:52px;height:52px;"> dummy1 <img src="cid:image002.png@01D8AC0A.08251CD1" style="width:52px;height:52px;"> dummy2 </p>
+        TEXT
+      end
     end
 
     context 'signature recognition' do