From 35a39c1d3476f0398a2846772e075b9a003bd623 Mon Sep 17 00:00:00 2001 From: Mario de la Ossa Date: Tue, 18 Jun 2019 19:28:18 -0600 Subject: Do not rewrite relative links for system notes --- app/models/note.rb | 2 +- changelogs/unreleased/bug-63162-duplicate_path_in_links.yml | 5 +++++ lib/banzai/filter/relative_link_filter.rb | 2 ++ spec/lib/banzai/filter/relative_link_filter_spec.rb | 7 +++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/bug-63162-duplicate_path_in_links.yml diff --git a/app/models/note.rb b/app/models/note.rb index 15271c68a9e..b55af7d9b5e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -457,7 +457,7 @@ class Note < ApplicationRecord end def banzai_render_context(field) - super.merge(noteable: noteable) + super.merge(noteable: noteable, system_note: system?) end def retrieve_upload(_identifier, paths) diff --git a/changelogs/unreleased/bug-63162-duplicate_path_in_links.yml b/changelogs/unreleased/bug-63162-duplicate_path_in_links.yml new file mode 100644 index 00000000000..d3f246492fb --- /dev/null +++ b/changelogs/unreleased/bug-63162-duplicate_path_in_links.yml @@ -0,0 +1,5 @@ +--- +title: Fixed 'diff version changes' link not working +merge_request: 29825 +author: +type: fixed diff --git a/lib/banzai/filter/relative_link_filter.rb b/lib/banzai/filter/relative_link_filter.rb index 199b3533cf4..80c84c0f622 100644 --- a/lib/banzai/filter/relative_link_filter.rb +++ b/lib/banzai/filter/relative_link_filter.rb @@ -17,6 +17,8 @@ module Banzai include Gitlab::Utils::StrongMemoize def call + return doc if context[:system_note] + @uri_types = {} clear_memoization(:linkable_files) diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index dad0a5535c0..8ff971114d6 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -101,6 +101,13 @@ describe Banzai::Filter::RelativeLinkFilter do .to eq "/#{project_path}/blob/#{ref}/doc/api/README.md" end + it 'does not modify relative URLs in system notes' do + path = "#{project_path}/merge_requests/1/diffs" + doc = filter(link(path), system_note: true) + + expect(doc.at_css('a')['href']).to eq path + end + it 'ignores absolute URLs with two leading slashes' do doc = filter(link('//doc/api/README.md')) expect(doc.at_css('a')['href']).to eq '//doc/api/README.md' -- cgit v1.2.1