From: Tom Hughes Date: Thu, 27 Mar 2025 17:30:12 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/5850' X-Git-Tag: live~77 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/7a64e03a24ee4465f0c3316f72e1404624e709c7?ds=sidebyside;hp=-c Merge remote-tracking branch 'upstream/pull/5850' --- 7a64e03a24ee4465f0c3316f72e1404624e709c7 diff --combined lib/rich_text.rb index 36e70063f,d2891ef66..1147cbc60 --- a/lib/rich_text.rb +++ b/lib/rich_text.rb @@@ -25,8 -25,6 +25,6 @@@ module RichTex end class Base < String - include ActionView::Helpers::TagHelper - def spam_score link_count = 0 link_size = 0 @@@ -76,25 -74,19 +74,25 @@@ end def linkify(text, mode = :urls) - link_attr = tag_builder.tag_options(:rel => "nofollow noopener noreferrer") + link_attr = 'rel="nofollow noopener noreferrer"' Rinku.auto_link(ERB::Util.html_escape(text), mode, link_attr) do |url| - %r{^https?://([^/]*)(.*)$}.match(url) do |m| - "#{Settings.linkify_hosts_replacement}#{m[2]}" if Settings.linkify_hosts_replacement && - Settings.linkify_hosts&.include?(m[1]) - end || url + url = shorten_host(url, Settings.linkify_hosts, Settings.linkify_hosts_replacement) + shorten_host(url, Settings.linkify_wiki_hosts, Settings.linkify_wiki_hosts_replacement) end.html_safe end + + private + + def shorten_host(url, hosts, hosts_replacement) + %r{^https?://([^/]*)(.*)$}.match(url) do |m| + "#{hosts_replacement}#{m[2]}" if hosts_replacement && hosts&.include?(m[1]) + end || url + end end class HTML < Base def to_html - linkify(sanitize(simple_format(self))) + linkify(simple_format(self)) end def to_text