Prevent Error 500s with invalid relative links
https://gitlab.com/gitlab-org/gitlab-ce/issues/52009
This commit is contained in:
parent
d924176117
commit
c92372e896
3 changed files with 15 additions and 1 deletions
5
changelogs/unreleased/sh-fix-issue-52009.yml
Normal file
5
changelogs/unreleased/sh-fix-issue-52009.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Prevent Error 500s with invalid relative links
|
||||
merge_request: 22001
|
||||
author:
|
||||
type: fixed
|
|
@ -60,7 +60,11 @@ module Banzai
|
|||
path_parts.unshift(relative_url_root, project.full_path)
|
||||
end
|
||||
|
||||
begin
|
||||
path = Addressable::URI.escape(File.join(*path_parts))
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
return
|
||||
end
|
||||
|
||||
html_attr.value =
|
||||
if context[:only_path]
|
||||
|
|
|
@ -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'])
|
||||
|
|
Loading…
Reference in a new issue