Commit f7348cd3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix cross-project label ref with invalid project

Closes #15168
parent 2ade37e2
...@@ -20,7 +20,7 @@ module Banzai ...@@ -20,7 +20,7 @@ module Banzai
text.gsub(pattern) do |match| text.gsub(pattern) do |match|
project = project_from_ref($~[:project]) project = project_from_ref($~[:project])
params = label_params($~[:label_id].to_i, $~[:label_name]) params = label_params($~[:label_id].to_i, $~[:label_name])
label = project.labels.find_by(params) label = project.labels.find_by(params) if project
if label if label
yield match, label.id, $~[:project], $~ yield match, label.id, $~[:project], $~
......
...@@ -178,27 +178,37 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do ...@@ -178,27 +178,37 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end end
describe 'cross project label references' do describe 'cross project label references' do
let(:another_project) { create(:empty_project, :public) } context 'valid project referenced' do
let(:project_name) { another_project.name_with_namespace } let(:another_project) { create(:empty_project, :public) }
let(:label) { create(:label, project: another_project, color: '#00ff00') } let(:project_name) { another_project.name_with_namespace }
let(:reference) { label.to_reference(project) } let(:label) { create(:label, project: another_project, color: '#00ff00') }
let(:reference) { label.to_reference(project) }
let!(:result) { reference_filter("See #{reference}") } let!(:result) { reference_filter("See #{reference}") }
it 'points to referenced project issues page' do it 'points to referenced project issues page' do
expect(result.css('a').first.attr('href')) expect(result.css('a').first.attr('href'))
.to eq urls.namespace_project_issues_url(another_project.namespace, .to eq urls.namespace_project_issues_url(another_project.namespace,
another_project, another_project,
label_name: label.name) label_name: label.name)
end end
it 'has valid color' do
expect(result.css('a span').first.attr('style'))
.to match /background-color: #00ff00/
end
it 'has valid color' do it 'contains cross project content' do
expect(result.css('a span').first.attr('style')) expect(result.css('a').first.text).to eq "#{label.name} in #{project_name}"
.to match /background-color: #00ff00/ end
end end
it 'contains cross project content' do context 'project that does not exist referenced' do
expect(result.css('a').first.text).to eq "#{label.name} in #{project_name}" let(:result) { reference_filter('aaa/bbb~ccc') }
it 'does not link reference' do
expect(result.to_html).to eq 'aaa/bbb~ccc'
end
end end
end 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