Commit 1b7fd53a authored by Sean McGivern's avatar Sean McGivern

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
parents c9267aaf c92372e8
---
title: Prevent Error 500s with invalid relative links
merge_request: 22001
author:
type: fixed
...@@ -60,7 +60,11 @@ module Banzai ...@@ -60,7 +60,11 @@ module Banzai
path_parts.unshift(relative_url_root, project.full_path) path_parts.unshift(relative_url_root, project.full_path)
end 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 = html_attr.value =
if context[:only_path] if context[:only_path]
......
...@@ -83,6 +83,11 @@ describe Banzai::Filter::RelativeLinkFilter do ...@@ -83,6 +83,11 @@ describe Banzai::Filter::RelativeLinkFilter do
expect { filter(act) }.not_to raise_error expect { filter(act) }.not_to raise_error
end 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 it 'ignores ref if commit is passed' do
doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') ) doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') )
expect(doc.at_css('a')['href']) expect(doc.at_css('a')['href'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment