Commit 94da20fd authored by Sean McGivern's avatar Sean McGivern

Merge branch 'dm-label-reference-period' into 'master'

Properly detect label reference if followed by period or question mark

See merge request gitlab-org/gitlab-ce!19965
parents 069c95e1 1753efbc
...@@ -85,11 +85,16 @@ class Label < ActiveRecord::Base ...@@ -85,11 +85,16 @@ class Label < ActiveRecord::Base
(#{Project.reference_pattern})? (#{Project.reference_pattern})?
#{Regexp.escape(reference_prefix)} #{Regexp.escape(reference_prefix)}
(?: (?:
(?<label_id>\d+(?!\S\w)\b) | # Integer-based label ID, or (?<label_id>\d+(?!\S\w)\b)
(?<label_name> | # Integer-based label ID, or
[A-Za-z0-9_\-\?\.&]+ | # String-based single-word label title, or (?<label_name>
".+?" # String-based multi-word label surrounded in quotes # String-based single-word label title, or
) [A-Za-z0-9_\-\?\.&]+
(?<!\.|\?)
|
# String-based multi-word label surrounded in quotes
".+?"
)
) )
}x }x
end end
......
---
title: Properly detect label reference if followed by period or question mark
merge_request:
author:
type: fixed
...@@ -148,9 +148,11 @@ describe Banzai::Filter::LabelReferenceFilter do ...@@ -148,9 +148,11 @@ describe Banzai::Filter::LabelReferenceFilter do
expect(doc.text).to eq 'See ?g.fm&' expect(doc.text).to eq 'See ?g.fm&'
end end
it 'links with adjacent text' do it 'does not include trailing punctuation', :aggregate_failures do
doc = reference_filter("Label (#{reference}).") ['.', ', ok?', '...', '?', '!', ': is that ok?'].each do |trailing_punctuation|
expect(doc.to_html).to match(%r(\(<a.+><span.+>\?g\.fm&amp;</span></a>\)\.)) doc = filter("Label #{reference}#{trailing_punctuation}")
expect(doc.to_html).to match(%r(<a.+><span.+>\?g\.fm&amp;</span></a>#{Regexp.escape(trailing_punctuation)}))
end
end end
it 'ignores invalid label names' do it 'ignores invalid label names' do
......
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