summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-01-24 00:07:14 +0000
committerNick Thomas <nick@gitlab.com>2019-01-24 00:07:14 +0000
commita949043df7e36376e9cb450adf91095961163056 (patch)
treefe10faa44e5a37a416b6a3f0fc764b69ed552046
parentde3af288ce4e478acf8ad7a89690e7215a2bf6a0 (diff)
parent494e00caa3c24480592833cf1b223e34c1a2bfb2 (diff)
downloadgitlab-ce-a949043df7e36376e9cb450adf91095961163056.tar.gz
Merge branch 'sh-fix-upload-snippets-with-relative-url-root' into 'master'
Fix 404s for snippet uploads when relative URL root used Closes #56280 See merge request gitlab-org/gitlab-ce!24588
-rw-r--r--changelogs/unreleased/sh-fix-upload-snippets-with-relative-url-root.yml5
-rw-r--r--lib/banzai/filter/relative_link_filter.rb2
-rw-r--r--spec/lib/banzai/filter/relative_link_filter_spec.rb54
3 files changed, 61 insertions, 0 deletions
diff --git a/changelogs/unreleased/sh-fix-upload-snippets-with-relative-url-root.yml b/changelogs/unreleased/sh-fix-upload-snippets-with-relative-url-root.yml
new file mode 100644
index 00000000000..8bc1e4b4f8a
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-upload-snippets-with-relative-url-root.yml
@@ -0,0 +1,5 @@
+---
+title: Fix 404s for snippet uploads when relative URL root used
+merge_request: 24588
+author:
+type: fixed
diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb
index 7acbc933adc..93e6d6470f1 100644
--- a/lib/banzai/filter/relative_link_filter.rb
+++ b/lib/banzai/filter/relative_link_filter.rb
@@ -58,6 +58,8 @@ module Banzai
path_parts.unshift(relative_url_root, 'groups', group.full_path, '-')
elsif project
path_parts.unshift(relative_url_root, project.full_path)
+ else
+ path_parts.unshift(relative_url_root)
end
begin
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb
index 415ded05e6e..dad0a5535c0 100644
--- a/spec/lib/banzai/filter/relative_link_filter_spec.rb
+++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb
@@ -353,5 +353,59 @@ describe Banzai::Filter::RelativeLinkFilter do
expect(doc.at_css('a')['href']).to eq 'http://example.com'
end
end
+
+ context 'to a personal snippet' do
+ let(:group) { nil }
+ let(:project) { nil }
+ let(:relative_path) { '/uploads/-/system/personal_snippet/6/674e4f07fbf0a7736c3439212896e51a/example.tar.gz' }
+
+ context 'with an absolute URL' do
+ let(:absolute_path) { Gitlab.config.gitlab.url + relative_path }
+ let(:only_path) { false }
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(absolute_path)
+ end
+ end
+
+ context 'with a relative URL root' do
+ let(:gitlab_root) { '/gitlab' }
+ let(:absolute_path) { Gitlab.config.gitlab.url + gitlab_root + relative_path }
+
+ before do
+ stub_config_setting(relative_url_root: gitlab_root)
+ end
+
+ context 'with an absolute URL' do
+ let(:only_path) { false }
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(absolute_path)
+ end
+ end
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(gitlab_root + relative_path)
+ end
+ end
+
+ it 'rewrites the link correctly' do
+ doc = filter(link(relative_path))
+
+ expect(doc.at_css('a')['href']).to eq(relative_path)
+ end
+
+ it 'does not modify absolute URL' do
+ doc = filter(link('http://example.com'))
+
+ expect(doc.at_css('a')['href']).to eq 'http://example.com'
+ end
+ end
end
end