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
text.gsub(pattern) do |match|
project = project_from_ref($~[:project])
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
yield match, label.id, $~[:project], $~
......
......@@ -178,6 +178,7 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
describe 'cross project label references' do
context 'valid project referenced' do
let(:another_project) { create(:empty_project, :public) }
let(:project_name) { another_project.name_with_namespace }
let(:label) { create(:label, project: another_project, color: '#00ff00') }
......@@ -201,4 +202,13 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
expect(result.css('a').first.text).to eq "#{label.name} in #{project_name}"
end
end
context 'project that does not exist referenced' do
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
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