summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-05-18 22:01:37 +0000
committerRobert Speicher <robert@gitlab.com>2017-05-18 22:01:37 +0000
commite5cc8e0aa81c3012eff5303543b11931158478cf (patch)
tree20a27a3df076504c678c89759a14b233cbe1c2aa
parent12762caf82f3ff7ea5775ae97bcb07ba94b46673 (diff)
parent110f5a16547865156c5cae10d0d6171dab442029 (diff)
downloadgitlab-ce-e5cc8e0aa81c3012eff5303543b11931158478cf.tar.gz
Merge branch 'dm-catch-uri-errors' into 'master'
Catch all URI errors in ExternalLinkFilter Closes #32076 See merge request !11494
-rw-r--r--changelogs/unreleased/dm-catch-uri-errors.yml4
-rw-r--r--lib/banzai/filter/external_link_filter.rb2
-rw-r--r--spec/lib/banzai/filter/external_link_filter_spec.rb7
3 files changed, 12 insertions, 1 deletions
diff --git a/changelogs/unreleased/dm-catch-uri-errors.yml b/changelogs/unreleased/dm-catch-uri-errors.yml
new file mode 100644
index 00000000000..8b635d321b3
--- /dev/null
+++ b/changelogs/unreleased/dm-catch-uri-errors.yml
@@ -0,0 +1,4 @@
+---
+title: Catch all URI errors in ExternalLinkFilter
+merge_request:
+author:
diff --git a/lib/banzai/filter/external_link_filter.rb b/lib/banzai/filter/external_link_filter.rb
index 7d15a0f6d44..d6327ef31cb 100644
--- a/lib/banzai/filter/external_link_filter.rb
+++ b/lib/banzai/filter/external_link_filter.rb
@@ -24,7 +24,7 @@ module Banzai
def uri(href)
URI.parse(href)
- rescue URI::InvalidURIError
+ rescue URI::Error
nil
end
diff --git a/spec/lib/banzai/filter/external_link_filter_spec.rb b/spec/lib/banzai/filter/external_link_filter_spec.rb
index 6f6c215be87..0f8ec8de7a0 100644
--- a/spec/lib/banzai/filter/external_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/external_link_filter_spec.rb
@@ -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