summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-08-20 18:25:16 -0700
committerRobert Speicher <rspeicher@gmail.com>2015-08-20 18:25:16 -0700
commit747fe7520b244a324b60049cbe22c22a5df29c82 (patch)
tree5432641ed04d21bb7ca8c3597c2ff00bb68874be
parent2de0935e276e45ac0090d32fd345593c2db92a5b (diff)
downloadgitlab-ce-rs-dev-issue-2550.tar.gz
Remove trailing HTML entities from non-Rinku autolinks as well.rs-dev-issue-2550
-rw-r--r--lib/gitlab/markdown/autolink_filter.rb8
-rw-r--r--spec/lib/gitlab/markdown/autolink_filter_spec.rb10
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/gitlab/markdown/autolink_filter.rb b/lib/gitlab/markdown/autolink_filter.rb
index 4e14a048cfb..541f1d88ffc 100644
--- a/lib/gitlab/markdown/autolink_filter.rb
+++ b/lib/gitlab/markdown/autolink_filter.rb
@@ -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
diff --git a/spec/lib/gitlab/markdown/autolink_filter_spec.rb b/spec/lib/gitlab/markdown/autolink_filter_spec.rb
index 982be0782c9..26332ba5217 100644
--- a/spec/lib/gitlab/markdown/autolink_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/autolink_filter_spec.rb
@@ -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 &lt;&lt;&lt;#{link}&gt;&gt;&gt;")
+
+ expect(doc.at_css('a')['href']).to eq link
+ expect(doc.text).to eq "See <<<#{link}>>>"
end
it 'accepts link_attr options' do