summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/gitlab/gfm/reference_rewriter.rb14
-rw-r--r--spec/lib/gitlab/gfm/reference_rewriter_spec.rb15
2 files changed, 19 insertions, 10 deletions
diff --git a/lib/gitlab/gfm/reference_rewriter.rb b/lib/gitlab/gfm/reference_rewriter.rb
index 91069732d44..edc96a5e83b 100644
--- a/lib/gitlab/gfm/reference_rewriter.rb
+++ b/lib/gitlab/gfm/reference_rewriter.rb
@@ -49,7 +49,7 @@ module Gitlab
def unfold_reference(reference, match, target_project)
before = @text[0...match.begin(0)]
after = @text[match.end(0)..-1]
- referable = find_local_referable(reference)
+ referable = find_referable(reference)
return reference unless referable
cross_reference = referable.to_reference(target_project)
@@ -58,17 +58,11 @@ module Gitlab
substitution_valid?(new_text) ? cross_reference : reference
end
- def referables
- return @referables if @referables
-
+ def find_referable(reference)
extractor = Gitlab::ReferenceExtractor.new(@source_project,
@current_user)
- extractor.analyze(@text)
- @referables = extractor.all
- end
-
- def find_local_referable(reference)
- referables.find { |ref| ref.to_reference == reference }
+ extractor.analyze(reference)
+ extractor.all.first
end
def substitution_valid?(substituted)
diff --git a/spec/lib/gitlab/gfm/reference_rewriter_spec.rb b/spec/lib/gitlab/gfm/reference_rewriter_spec.rb
index db7bee110af..0a7ca3ec848 100644
--- a/spec/lib/gitlab/gfm/reference_rewriter_spec.rb
+++ b/spec/lib/gitlab/gfm/reference_rewriter_spec.rb
@@ -61,6 +61,21 @@ describe Gitlab::Gfm::ReferenceRewriter do
it { is_expected.to eq "#{ref}, `#1`, #{ref}, `#1`" }
end
+
+ context 'description with labels' do
+ let!(:label) { create(:label, id: 123, name: 'test', project: old_project) }
+ let(:project_ref) { old_project.to_reference }
+
+ context 'label referenced by id' do
+ let(:text) { '#1 and ~123' }
+ it { is_expected.to eq %Q{#{project_ref}#1 and #{project_ref}~123} }
+ end
+
+ context 'label referenced by text' do
+ let(:text) { '#1 and ~"test"' }
+ it { is_expected.to eq %Q{#{project_ref}#1 and #{project_ref}~123} }
+ end
+ end
end
context 'reference contains milestone' do