remove_last_empty_node_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe HtmlSanitizer::Scrubber::RemoveLastEmptyNode do
  4. let(:scrubber) { described_class.new }
  5. describe('#scrubber') do
  6. subject(:actual) do
  7. # export with extra options to avoid html indentation
  8. fragment.scrub!(scrubber)
  9. .to_html save_with: Nokogiri::XML::Node::SaveOptions::DEFAULT_HTML ^ Nokogiri::XML::Node::SaveOptions::FORMAT
  10. end
  11. let(:fragment) { Loofah.fragment(input) }
  12. context 'when empty b node' do
  13. let(:input) { '<div>asd<b></b></div>' }
  14. let(:target) { '<div>asd</div>' }
  15. it { is_expected.to eq target }
  16. end
  17. context 'when empty div' do
  18. let(:input) { '<div>asd<div></div></div>' }
  19. let(:target) { '<div>asd</div>' }
  20. it { is_expected.to eq target }
  21. end
  22. context 'when not empty div' do
  23. let(:input) { '<div>asd<div>qwe</div></div>' }
  24. let(:target) { '<div>asd<div>qwe</div></div>' }
  25. it { is_expected.to eq target }
  26. end
  27. context 'when tag has another tag' do
  28. let(:input) { '<tag>asd<another-tag></another-tag></tag>' }
  29. let(:target) { '<tag>asd<another-tag></another-tag></tag>' }
  30. it { is_expected.to eq target }
  31. end
  32. context 'when tag has same tag' do
  33. let(:input) { '<tag><tag></tag></tag>' }
  34. let(:target) { '<tag></tag>' }
  35. it { is_expected.to eq target }
  36. end
  37. context 'when tag has same tag with attributes' do
  38. let(:input) { '<tag><tag attr="true"></tag></tag>' }
  39. let(:target) { '<tag attr="true"></tag>' }
  40. it { is_expected.to eq target }
  41. end
  42. end
  43. end