diff options
-rw-r--r-- | changelogs/unreleased/sh-fix-issue-63910.yml | 5 | ||||
-rw-r--r-- | lib/banzai/filter/relative_link_filter.rb | 6 | ||||
-rw-r--r-- | spec/helpers/markup_helper_spec.rb | 37 |
3 files changed, 45 insertions, 3 deletions
diff --git a/changelogs/unreleased/sh-fix-issue-63910.yml b/changelogs/unreleased/sh-fix-issue-63910.yml new file mode 100644 index 00000000000..50312558c57 --- /dev/null +++ b/changelogs/unreleased/sh-fix-issue-63910.yml @@ -0,0 +1,5 @@ +--- +title: Fix attachments using the wrong URLs in e-mails +merge_request: 30197 +author: +type: fixed diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb index 80c84c0f622..88836e12e61 100644 --- a/lib/banzai/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -56,10 +56,10 @@ module Banzai def process_link_to_upload_attr(html_attr) path_parts = [Addressable::URI.unescape(html_attr.value)] - if group - path_parts.unshift(relative_url_root, 'groups', group.full_path, '-') - elsif project + if project path_parts.unshift(relative_url_root, project.full_path) + elsif group + path_parts.unshift(relative_url_root, 'groups', group.full_path, '-') else path_parts.unshift(relative_url_root) end diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 597c8f836a9..6c6410cee9b 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -50,6 +50,43 @@ describe MarkupHelper do expect(markdown(actual, project: second_project)).to match(expected) end end + + describe 'uploads' do + let(:text) { "![ImageTest](/uploads/test.png)" } + let(:group) { create(:group) } + + subject { helper.markdown(text) } + + describe 'inside a project' do + it 'renders uploads relative to project' do + expect(subject).to include("#{project.full_path}/uploads/test.png") + end + end + + describe 'inside a group' do + before do + helper.instance_variable_set(:@group, group) + helper.instance_variable_set(:@project, nil) + end + + it 'renders uploads relative to the group' do + expect(subject).to include("#{group.full_path}/-/uploads/test.png") + end + end + + describe "with a group in the context" do + let(:project_in_group) { create(:project, group: group) } + + before do + helper.instance_variable_set(:@group, group) + helper.instance_variable_set(:@project, project_in_group) + end + + it 'renders uploads relative to project' do + expect(subject).to include("#{project_in_group.path_with_namespace}/uploads/test.png") + end + end + end end describe '#markdown_field' do |