summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-05-10 13:46:04 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-05-10 13:50:56 +0200
commit535be93a77ec677dbb561f8c1545a60d0d908832 (patch)
tree10ccd88cfb207c5ff2e481d3d19c26a6ad0dd632
parentc97a81d274ff0e7b792ed409385318c4ec25d92e (diff)
downloadgitlab-ce-535be93a77ec677dbb561f8c1545a60d0d908832.tar.gz
Do not process upload links if no project context
-rw-r--r--lib/banzai/filter/upload_link_filter.rb8
-rw-r--r--spec/lib/banzai/filter/upload_link_filter_spec.rb6
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/banzai/filter/upload_link_filter.rb b/lib/banzai/filter/upload_link_filter.rb
index 483d40c46df..c0f503c9af3 100644
--- a/lib/banzai/filter/upload_link_filter.rb
+++ b/lib/banzai/filter/upload_link_filter.rb
@@ -8,6 +8,8 @@ module Banzai
#
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 @@ module Banzai
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!
diff --git a/spec/lib/banzai/filter/upload_link_filter_spec.rb b/spec/lib/banzai/filter/upload_link_filter_spec.rb
index 7a7103079ea..b83be54746c 100644
--- a/spec/lib/banzai/filter/upload_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/upload_link_filter_spec.rb
@@ -79,13 +79,13 @@ describe Banzai::Filter::UploadLinkFilter, lib: true do
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