You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.8 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Sanitize::Config do
  4. describe '::MASTODON_STRICT' do
  5. subject { Sanitize::Config::MASTODON_STRICT }
  6. it 'converts h1 to p' do
  7. expect(Sanitize.fragment('<h1>Foo</h1>', subject)).to eq '<p>Foo</p>'
  8. end
  9. it 'converts ul to p' do
  10. expect(Sanitize.fragment('<p>Check out:</p><ul><li>Foo</li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><p>Foo<br>Bar</p>'
  11. end
  12. it 'converts p inside ul' do
  13. expect(Sanitize.fragment('<ul><li><p>Foo</p><p>Bar</p></li><li>Baz</li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
  14. end
  15. it 'converts ul inside ul' do
  16. expect(Sanitize.fragment('<ul><li>Foo</li><li><ul><li>Bar</li><li>Baz</li></ul></li></ul>', subject)).to eq '<p>Foo<br>Bar<br>Baz</p>'
  17. end
  18. it 'keep links in lists' do
  19. expect(Sanitize.fragment('<p>Check out:</p><ul><li><a href="https://joinmastodon.org" rel="nofollow noopener noreferrer" target="_blank">joinmastodon.org</a></li><li>Bar</li></ul>', subject)).to eq '<p>Check out:</p><p><a href="https://joinmastodon.org" rel="nofollow noopener noreferrer" target="_blank">joinmastodon.org</a><br>Bar</p>'
  20. end
  21. it 'removes a without href' do
  22. expect(Sanitize.fragment('<a>Test</a>', subject)).to eq 'Test'
  23. end
  24. it 'removes a without href and only keeps text content' do
  25. expect(Sanitize.fragment('<a><span class="invisible">foo&amp;</span><span>Test</span></a>', subject)).to eq 'foo&amp;Test'
  26. end
  27. it 'removes a with unsupported scheme in href' do
  28. expect(Sanitize.fragment('<a href="foo://bar">Test</a>', subject)).to eq 'Test'
  29. end
  30. it 'keeps a with href' do
  31. expect(Sanitize.fragment('<a href="http://example.com">Test</a>', subject)).to eq '<a href="http://example.com" rel="nofollow noopener noreferrer" target="_blank">Test</a>'
  32. end
  33. end
  34. end