diff options
author | Marin Jankovski <marin@gitlab.com> | 2018-03-29 11:43:13 +0000 |
---|---|---|
committer | Marin Jankovski <marin@gitlab.com> | 2018-03-29 11:43:13 +0000 |
commit | 7d1576425188fe40c0633ee7d20102fcac0b8f9a (patch) | |
tree | 0088b35262b62fe8436acfad7a8e9b39ab2cad8a | |
parent | 4380c0e771991983397d4efee1c8e029646ca559 (diff) | |
parent | 60c5c8a988d9c123fd44f69eaf0e5f80f8d2116e (diff) | |
download | gitlab-ce-7d1576425188fe40c0633ee7d20102fcac0b8f9a.tar.gz |
Merge branch 'cherry-pick-058dd1' into '10-6-stable'
[10.6] Autolinking includes trailing exclamation marks
See merge request gitlab-org/gitlab-ce!18077
-rw-r--r-- | changelogs/unreleased/44587-autolinking-includes-trailing-exclamation-marks.yml | 5 | ||||
-rw-r--r-- | lib/banzai/filter/autolink_filter.rb | 11 | ||||
-rw-r--r-- | spec/lib/banzai/filter/autolink_filter_spec.rb | 12 |
3 files changed, 15 insertions, 13 deletions
diff --git a/changelogs/unreleased/44587-autolinking-includes-trailing-exclamation-marks.yml b/changelogs/unreleased/44587-autolinking-includes-trailing-exclamation-marks.yml new file mode 100644 index 00000000000..636fde601ee --- /dev/null +++ b/changelogs/unreleased/44587-autolinking-includes-trailing-exclamation-marks.yml @@ -0,0 +1,5 @@ +--- +title: Don't capture trailing punctuation when autolinking +merge_request: 17965 +author: +type: fixed diff --git a/lib/banzai/filter/autolink_filter.rb b/lib/banzai/filter/autolink_filter.rb index 75b64ae9af2..ce401c1c31c 100644 --- a/lib/banzai/filter/autolink_filter.rb +++ b/lib/banzai/filter/autolink_filter.rb @@ -21,12 +21,13 @@ module Banzai # # See http://en.wikipedia.org/wiki/URI_scheme # - # The negative lookbehind ensures that users can paste a URL followed by a - # period or comma for punctuation without those characters being included - # in the generated link. + # The negative lookbehind ensures that users can paste a URL followed by + # punctuation without those characters being included in the generated + # link. It matches the behaviour of Rinku 2.0.1: + # https://github.com/vmg/rinku/blob/v2.0.1/ext/rinku/autolink.c#L65 # - # Rubular: http://rubular.com/r/JzPhi6DCZp - LINK_PATTERN = %r{([a-z][a-z0-9\+\.-]+://[^\s>]+)(?<!,|\.)} + # Rubular: http://rubular.com/r/nrL3r9yUiq + LINK_PATTERN = %r{([a-z][a-z0-9\+\.-]+://[^\s>]+)(?<!\?|!|\.|,|:)} # Text matching LINK_PATTERN inside these elements will not be linked IGNORE_PARENTS = %w(a code kbd pre script style).to_set diff --git a/spec/lib/banzai/filter/autolink_filter_spec.rb b/spec/lib/banzai/filter/autolink_filter_spec.rb index b502daea418..cbb0089bde7 100644 --- a/spec/lib/banzai/filter/autolink_filter_spec.rb +++ b/spec/lib/banzai/filter/autolink_filter_spec.rb @@ -122,14 +122,10 @@ describe Banzai::Filter::AutolinkFilter do end it 'does not include trailing punctuation' do - doc = filter("See #{link}.") - expect(doc.at_css('a').text).to eq link - - doc = filter("See #{link}, ok?") - expect(doc.at_css('a').text).to eq link - - doc = filter("See #{link}...") - expect(doc.at_css('a').text).to eq link + ['.', ', ok?', '...', '?', '!', ': is that ok?'].each do |trailing_punctuation| + doc = filter("See #{link}#{trailing_punctuation}") + expect(doc.at_css('a').text).to eq link + end end it 'includes trailing punctuation when part of a balanced pair' do |