remove_line_breaks_spec.rb 1015 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe HtmlSanitizer::RemoveLineBreaks do
  4. let(:scrubber) { described_class.new }
  5. describe('#scrubber') do
  6. subject(:actual) { fragment.scrub!(scrubber).to_html }
  7. let(:fragment) { Loofah.fragment(input) }
  8. describe 'removes newline-only spans' do
  9. let(:input) { "<div>test<span>a\n</span><span>\r\n</span></div>" }
  10. let(:target) { "<div>testa\n</div>" }
  11. it { is_expected.to match target }
  12. end
  13. describe 'removes newline-only in divs' do
  14. let(:input) { "<div>test<div>a\n</div><div>\r\n\n\n</div></div>" }
  15. let(:target) { "<div>test<div>a\n</div>\n</div>" }
  16. it { is_expected.to match target }
  17. end
  18. describe 'does not remove newlines in other elements' do
  19. let(:input) { "<div>test<output>a\n</output></div>" }
  20. let(:target) { "<div>test<output>a\n</output>\n</div>" }
  21. it { is_expected.to match target }
  22. end
  23. end
  24. end