summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-12 18:33:37 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-13 11:42:31 -0300
commitc88075f46772d3c462969372fafbd7f3886872b8 (patch)
tree5dd2d2027d3d9d69dafa196bf6978b120bb8013f
parent4be505bfd177755103d74ca4874086853a32449a (diff)
downloadgitlab-ce-c88075f46772d3c462969372fafbd7f3886872b8.tar.gz
Fix markdown rendering for consecutive label references
-rw-r--r--app/models/label.rb2
-rw-r--r--spec/lib/banzai/filter/label_reference_filter_spec.rb40
2 files changed, 41 insertions, 1 deletions
diff --git a/app/models/label.rb b/app/models/label.rb
index dc5586f5756..60c0fff44ce 100644
--- a/app/models/label.rb
+++ b/app/models/label.rb
@@ -59,7 +59,7 @@ class Label < ActiveRecord::Base
(?<label_id>\d+) | # Integer-based label ID, or
(?<label_name>
[A-Za-z0-9_\-\?&]+ | # String-based single-word label title, or
- "[^,]+" # String-based multi-word label surrounded in quotes
+ "([^"]*)" # String-based multi-word label surrounded in quotes
)
)
}x
diff --git a/spec/lib/banzai/filter/label_reference_filter_spec.rb b/spec/lib/banzai/filter/label_reference_filter_spec.rb
index 9e3d2f5825d..b16470718a0 100644
--- a/spec/lib/banzai/filter/label_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/label_reference_filter_spec.rb
@@ -178,6 +178,46 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
+ describe 'consecutive references' do
+ let(:bug) { create(:label, name: 'bug', project: project) }
+ let(:feature_proposal) { create(:label, name: 'feature proposal', project: project) }
+ let(:technical_debt) { create(:label, name: 'technical debt', project: project) }
+
+ let(:bug_reference) { "#{Label.reference_prefix}#{bug.name}" }
+ let(:feature_proposal_reference) { feature_proposal.to_reference(format: :name) }
+ let(:technical_debt_reference) { technical_debt.to_reference(format: :name) }
+
+ context 'separated with a comma' do
+ let(:references) { "#{bug_reference}, #{feature_proposal_reference}, #{technical_debt_reference}" }
+
+ it 'links to valid references' do
+ doc = reference_filter("See #{references}")
+
+ expect(doc.css('a').map { |a| a.attr('href') }).to match_array([
+ urls.namespace_project_issues_url(project.namespace, project, label_name: bug.name),
+ urls.namespace_project_issues_url(project.namespace, project, label_name: feature_proposal.name),
+ urls.namespace_project_issues_url(project.namespace, project, label_name: technical_debt.name)
+ ])
+ expect(doc.text).to eq 'See bug, feature proposal, technical debt'
+ end
+ end
+
+ context 'separated with a space' do
+ let(:references) { "#{bug_reference} #{feature_proposal_reference} #{technical_debt_reference}" }
+
+ it 'links to valid references' do
+ doc = reference_filter("See #{references}")
+
+ expect(doc.css('a').map { |a| a.attr('href') }).to match_array([
+ urls.namespace_project_issues_url(project.namespace, project, label_name: bug.name),
+ urls.namespace_project_issues_url(project.namespace, project, label_name: feature_proposal.name),
+ urls.namespace_project_issues_url(project.namespace, project, label_name: technical_debt.name)
+ ])
+ expect(doc.text).to eq 'See bug feature proposal technical debt'
+ end
+ end
+ end
+
describe 'edge cases' do
it 'gracefully handles non-references matching the pattern' do
exp = act = '(format nil "~0f" 3.0) ; 3.0'