Skip to content

Commit

Permalink
Fix link sanitization for outgoing text/html and text/markdown toots
Browse files Browse the repository at this point in the history
Fixes #1739
  • Loading branch information
ClearlyClaire committed Apr 11, 2022
1 parent 9309c53 commit f2b2614
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/sanitize_ext/sanitize_config.rb
Expand Up @@ -133,7 +133,7 @@ module Config
rel += ['nofollow', 'noopener', 'noreferrer'] unless TagManager.instance.local_url?(node['href'])

if rel.empty?
node['rel']&.delete
node.remove_attribute('rel')
else
node['rel'] = rel.join(' ')
end
Expand All @@ -144,7 +144,7 @@ module Config

node = env[:node]
if node['target'] != '_blank' && TagManager.instance.local_url?(node['href'])
node['target']&.delete
node.remove_attribute('target')
else
node['target'] = '_blank'
end
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/advanced_text_formatter_spec.rb
Expand Up @@ -50,6 +50,14 @@
end
end

context 'given text with a local-domain mention' do
let(:text) { 'foo https://cb6e6126.ngrok.io/about/more' }

it 'creates a link' do
is_expected.to include '<a href="https://cb6e6126.ngrok.io/about/more"'
end
end

context 'given text containing linkable mentions' do
let(:preloaded_accounts) { [Fabricate(:account, username: 'alice')] }
let(:text) { '@alice' }
Expand Down

0 comments on commit f2b2614

Please sign in to comment.