Commit 5b1ed003 authored by Robert Speicher's avatar Robert Speicher Committed by Mayra Cabrera
Browse files

Merge branch '44587-autolinking-includes-trailing-exclamation-marks' into 'master'

Resolve "Autolinking includes trailing exclamation marks"

Closes #44587

See merge request gitlab-org/gitlab-ce!17965
parent 6f9b7bbf
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
---
title: Don't capture trailing punctuation when autolinking
merge_request: 17965
author:
type: fixed
+6 −5
Original line number Diff line number Diff line
@@ -21,12 +21,13 @@ class AutolinkFilter < HTML::Pipeline::Filter
      #
      # 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
+4 −8
Original line number Diff line number Diff line
@@ -122,15 +122,11 @@
    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}...")
      ['.', ', 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
      described_class::PUNCTUATION_PAIRS.each do |close, open|