Catch all URI errors in ExternalLinkFilter

This commit is contained in:
Douwe Maan 2017-05-18 10:47:18 -05:00
parent b46b52af37
commit 110f5a1654
3 changed files with 12 additions and 1 deletions

View file

@ -0,0 +1,4 @@
---
title: Catch all URI errors in ExternalLinkFilter
merge_request:
author:

View file

@ -24,7 +24,7 @@ module Banzai
def uri(href)
URI.parse(href)
rescue URI::InvalidURIError
rescue URI::Error
nil
end

View file

@ -55,6 +55,13 @@ describe Banzai::Filter::ExternalLinkFilter, lib: true do
expect(doc.to_html).to eq(expected)
end
it 'skips improperly formatted mailtos' do
doc = filter %q(<p><a href="mailto://jblogs@example.com">Email</a></p>)
expected = %q(<p><a href="mailto://jblogs@example.com">Email</a></p>)
expect(doc.to_html).to eq(expected)
end
end
context 'for links with a username' do