diff --git a/app/models/concerns/checks_html_sanitized.rb b/app/models/concerns/checks_html_sanitized.rb index 147125a8e..5f40caee5 100644 --- a/app/models/concerns/checks_html_sanitized.rb +++ b/app/models/concerns/checks_html_sanitized.rb @@ -12,6 +12,8 @@ module ChecksHtmlSanitized return true if html_attributes.blank? html_attributes.each do |attribute| + next if changes[attribute].blank? + value = send(attribute) next if value.blank? diff --git a/spec/models/ticket/article_spec.rb b/spec/models/ticket/article_spec.rb index 7287e7efa..2583cfc59 100644 --- a/spec/models/ticket/article_spec.rb +++ b/spec/models/ticket/article_spec.rb @@ -126,6 +126,24 @@ RSpec.describe Ticket::Article, type: :model do foo SANITIZED end + + context 'when a sanitization attribute is present' do + # ATTENTION: We use `target` here because re-sanitization would change the order of attributes + let(:body) { 'foo' } + + it 'adds sanitization attributes' do + expect(article.body).to eq(<<~SANITIZED.chomp) + foo + SANITIZED + end + + context 'when changing an unrelated attribute' do + + it "doesn't re-sanitizes the body" do + expect { article.update!(message_id: 'test') }.not_to change { article.reload.body } + end + end + end end context 'for all cases above, combined' do