GitLab wurde erfolgreich aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Danke für Ihre Geduld.

Commit 535be93a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Do not process upload links if no project context

parent c97a81d2
......@@ -8,6 +8,8 @@ module Filter
#
class UploadLinkFilter < HTML::Pipeline::Filter
def call
return doc unless project
doc.search('a').each do |el|
process_link_attr el.attribute('href')
end
......@@ -31,11 +33,13 @@ def process_link_attr(html_attr)
end
def build_url(uri)
return '#' unless project = context[:project]
File.join(Gitlab.config.gitlab.url, project.path_with_namespace, uri)
end
def project
context[:project]
end
# Ensure that a :project key exists in context
#
# Note that while the key might exist, its value could be nil!
......
......@@ -79,13 +79,13 @@ def link(path)
let(:upload_link) { link('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg') }
it 'does not raise error' do
expect { raw_filter(upload_link, project: nil) }.to_not raise_error
expect { raw_filter(upload_link, project: nil) }.not_to raise_error
end
it 'provides an empty link' do
it 'does not rewrite link' do
doc = raw_filter(upload_link, project: nil)
expect(doc.at_css('a')['href']).to eq '#'
expect(doc.to_html).to eq upload_link
end
end
end
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