Remove trailing HTML entities from non-Rinku autolinks as well.

This commit is contained in:
Robert Speicher 2015-08-20 18:25:16 -07:00
parent 2de0935e27
commit 747fe7520b
2 changed files with 17 additions and 1 deletions

View File

@ -87,8 +87,14 @@ module Gitlab
def autolink_filter(text)
text.gsub(LINK_PATTERN) do |match|
# Remove any trailing HTML entities and store them for appending
# outside the link element. The entity must be marked HTML safe in
# order to be output literally rather than escaped.
match.gsub!(/((?:&[\w#]+;)+)\z/, '')
dropped = ($1 || '').html_safe
options = link_options.merge(href: match)
content_tag(:a, match, options)
content_tag(:a, match, options) + dropped
end
end

View File

@ -86,6 +86,16 @@ module Gitlab::Markdown
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
end
it 'does not include trailing HTML entities' do
doc = filter("See <<<#{link}>>>")
expect(doc.at_css('a')['href']).to eq link
expect(doc.text).to eq "See <<<#{link}>>>"
end
it 'accepts link_attr options' do