Skip to content

Commit 610731b

Browse files
Merge pull request from GHSA-55j9-c3mp-6fcq
1 parent c592979 commit 610731b

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

Diff for: app/helpers/formatting_helper.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def account_bio_format(account)
5454
end
5555

5656
def account_field_value_format(field, with_rel_me: true)
57-
html_aware_format(field.value, field.account.local?, with_rel_me: with_rel_me, with_domains: true, multiline: false)
57+
if field.verified? && !field.account.local?
58+
TextFormatter.shortened_link(field.value_for_verification)
59+
else
60+
html_aware_format(field.value, field.account.local?, with_rel_me: with_rel_me, with_domains: true, multiline: false)
61+
end
5862
end
5963
end

Diff for: app/lib/text_formatter.rb

+21-13
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ def to_s
4848
html.html_safe # rubocop:disable Rails/OutputSafety
4949
end
5050

51+
class << self
52+
include ERB::Util
53+
54+
def shortened_link(url, rel_me: false)
55+
url = Addressable::URI.parse(url).to_s
56+
rel = rel_me ? (DEFAULT_REL + %w(me)) : DEFAULT_REL
57+
58+
prefix = url.match(URL_PREFIX_REGEX).to_s
59+
display_url = url[prefix.length, 30]
60+
suffix = url[prefix.length + 30..-1]
61+
cutoff = url[prefix.length..-1].length > 30
62+
63+
<<~HTML.squish
64+
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}" translate="no"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
65+
HTML
66+
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
67+
h(url)
68+
end
69+
end
70+
5171
private
5272

5373
def rewrite
@@ -70,19 +90,7 @@ def rewrite
7090
end
7191

7292
def link_to_url(entity)
73-
url = Addressable::URI.parse(entity[:url]).to_s
74-
rel = with_rel_me? ? (DEFAULT_REL + %w(me)) : DEFAULT_REL
75-
76-
prefix = url.match(URL_PREFIX_REGEX).to_s
77-
display_url = url[prefix.length, 30]
78-
suffix = url[prefix.length + 30..-1]
79-
cutoff = url[prefix.length..-1].length > 30
80-
81-
<<~HTML.squish
82-
<a href="#{h(url)}" target="_blank" rel="#{rel.join(' ')}" translate="no"><span class="invisible">#{h(prefix)}</span><span class="#{cutoff ? 'ellipsis' : ''}">#{h(display_url)}</span><span class="invisible">#{h(suffix)}</span></a>
83-
HTML
84-
rescue Addressable::URI::InvalidURIError, IDN::Idna::IdnaError
85-
h(entity[:url])
93+
TextFormatter.shortened_link(entity[:url], rel_me: with_rel_me?)
8694
end
8795

8896
def link_to_hashtag(entity)

0 commit comments

Comments
 (0)