From 2c0441acd7f943a9873b650cf75d33c73d545acf Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Mar 2024 05:19:54 -0400 Subject: [PATCH] Use rails built-in `tag` methods in `TextFormatter.shortened_link` (#28976) --- app/lib/text_formatter.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/lib/text_formatter.rb b/app/lib/text_formatter.rb index 581ee835b3..2b3febc219 100644 --- a/app/lib/text_formatter.rb +++ b/app/lib/text_formatter.rb @@ -50,6 +50,7 @@ class TextFormatter class << self include ERB::Util + include ActionView::Helpers::TagHelper def shortened_link(url, rel_me: false) url = Addressable::URI.parse(url).to_s @@ -60,9 +61,11 @@ class TextFormatter suffix = url[prefix.length + 30..] cutoff = url[prefix.length..].length > 30 - <<~HTML.squish.html_safe # rubocop:disable Rails/OutputSafety - #{h(display_url)} - HTML + tag.a href: url, target: '_blank', rel: rel.join(' '), translate: 'no' do + tag.span(prefix, class: 'invisible') + + tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) + + tag.span(suffix, class: 'invisible') + end rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError h(url) end