diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 6f69c2a9f329a4a19e84c5f9b14e388f312ba232..44a8c9e32bbfdaabd538784cae4fdbebb7982076 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -181,6 +181,10 @@ module EventsHelper sanitize(text, tags: %w(a img b pre code p span)) end + def event_commit_urls(message) + URI.extract(message) + end + def event_commit_title(message) escape_once(truncate(message.split("\n").first, length: 70)) rescue diff --git a/app/views/events/_commit.html.haml b/app/views/events/_commit.html.haml index ad63841ccf3fee2d9f7ec3870a7a3637935b2aff..e69cad5d1366804438501bd7175168b7519ede5b 100644 --- a/app/views/events/_commit.html.haml +++ b/app/views/events/_commit.html.haml @@ -2,4 +2,4 @@ .commit-row-title = link_to truncate_sha(commit[:id]), namespace_project_commit_path(project.namespace, project, commit[:id]), class: "commit_short_id", alt: '' · - = gfm event_commit_title(commit[:message]), project: project + = gfm event_commit_title(commit[:message]), project: project, hrefs: event_commit_urls(commit[:message]) diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 32a368c2e2beda201bb63eb4b28251eda26bb390..1ed9c85856e897f2e2980b98eb87871c16ccf76e 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -102,6 +102,13 @@ module Gitlab save_options |= Nokogiri::XML::Node::SaveOptions::AS_XHTML end + uri_regex = /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ + result[:output].children.select{|klass| klass.name == "a"}.map! do |a_class| + unless a_class["href"] =~ uri_regex + a_class["href"] = options[:hrefs].select{|url| url.match(a_class["href"])}.first + end + end + text = result[:output].to_html(save_with: save_options) text.html_safe