diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2020-02-08 21:22:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-08 21:22:38 +0100 |
commit | b1349342d200937665ca6486c4b3ba1bae2f9d05 (patch) | |
tree | e1c1c157f4e756b55fc86d3b9207b815ce2e4e34 /spec/lib | |
parent | b686e275e7651532b2203083717d5ef88acb04b1 (diff) |
Fix rendering `<a>` without `href` when scheme unsupported (#13040)
- Disallow links with relative paths - Disallow iframes with non-http protocols and relative paths Close #13037
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/sanitize_config_spec.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/spec/lib/sanitize_config_spec.rb b/spec/lib/sanitize_config_spec.rb index feb86af35..d66302e64 100644 --- a/spec/lib/sanitize_config_spec.rb +++ b/spec/lib/sanitize_config_spec.rb @@ -26,5 +26,21 @@ describe Sanitize::Config do it 'keep links in lists' do 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>' end + + it 'removes a without href' do + expect(Sanitize.fragment('<a>Test</a>', subject)).to eq 'Test' + end + + it 'removes a without href and only keeps text content' do + expect(Sanitize.fragment('<a><span class="invisible">foo&</span><span>Test</span></a>', subject)).to eq 'foo&Test' + end + + it 'removes a with unsupported scheme in href' do + expect(Sanitize.fragment('<a href="foo://bar">Test</a>', subject)).to eq 'Test' + end + + it 'keeps a with href' do + 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>' + end end end |