summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-10-01 14:21:05 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-10-01 14:21:05 +0000
commit1b7fd53ae37bb7836e7fd3be80077717d1b3cd4d (patch)
tree58db6080e20be0256274be7e552113a2751d7ea4
parentc9267aafc6864792333a9b106a5ef897d21fccdb (diff)
parentc92372e896959d682dc70454a00f47672ca3bb9d (diff)
downloadgitlab-ce-1b7fd53ae37bb7836e7fd3be80077717d1b3cd4d.tar.gz
Merge branch 'sh-fix-issue-52009' into 'master'
Prevent Error 500s with invalid relative links Closes #52009 See merge request gitlab-org/gitlab-ce!22001
-rw-r--r--changelogs/unreleased/sh-fix-issue-52009.yml5
-rw-r--r--lib/banzai/filter/relative_link_filter.rb6
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb5
3 files changed, 15 insertions, 1 deletions
diff --git a/changelogs/unreleased/sh-fix-issue-52009.yml b/changelogs/unreleased/sh-fix-issue-52009.yml
new file mode 100644
index 00000000000..fc22a58a66a
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-issue-52009.yml
@@ -0,0 +1,5 @@
+---
+title: Prevent Error 500s with invalid relative links
+merge_request: 22001
+author:
+type: fixed
diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb
index 8e838d04bad..7acbc933adc 100644
--- a/lib/banzai/filter/relative_link_filter.rb
+++ b/lib/banzai/filter/relative_link_filter.rb
@@ -60,7 +60,11 @@ module Banzai
path_parts.unshift(relative_url_root, project.full_path)
end
- path = Addressable::URI.escape(File.join(*path_parts))
+ begin
+ path = Addressable::URI.escape(File.join(*path_parts))
+ rescue Addressable::URI::InvalidURIError
+ return
+ end
html_attr.value =
if context[:only_path]
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index ba8dc68ceda..ed1ebe9ebf6 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -83,6 +83,11 @@ describe Banzai::Filter::RelativeLinkFilter do
expect { filter(act) }.not_to raise_error
end
+ it 'does not raise an exception with a space in the path' do
+ act = link("/uploads/d18213acd3732630991986120e167e3d/Landscape_8.jpg \nBut here's some more unexpected text :smile:)")
+ expect { filter(act) }.not_to raise_error
+ end
+
it 'ignores ref if commit is passed' do
doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') )
expect(doc.at_css('a')['href'])