mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-29 14:35:06 +01:00
Change URL truncation to account for ellipses (#33229)
This commit is contained in:
parent
2131e61548
commit
c8c916e657
@ -68,6 +68,12 @@ class TextFormatter
|
|||||||
suffix = url[prefix.length + 30..]
|
suffix = url[prefix.length + 30..]
|
||||||
cutoff = url[prefix.length..].length > 30
|
cutoff = url[prefix.length..].length > 30
|
||||||
|
|
||||||
|
if suffix && suffix.length == 1 # revert truncation to account for ellipsis
|
||||||
|
display_url += suffix
|
||||||
|
suffix = nil
|
||||||
|
cutoff = false
|
||||||
|
end
|
||||||
|
|
||||||
tag.a href: url, target: '_blank', rel: rel.join(' '), translate: 'no' do
|
tag.a href: url, target: '_blank', rel: rel.join(' '), translate: 'no' do
|
||||||
tag.span(prefix, class: 'invisible') +
|
tag.span(prefix, class: 'invisible') +
|
||||||
tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) +
|
tag.span(display_url, class: (cutoff ? 'ellipsis' : '')) +
|
||||||
|
@ -50,7 +50,7 @@ RSpec.describe TextFormatter do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when given a stand-alone google URL' do
|
context 'when given a stand-alone Google URL' do
|
||||||
let(:text) { 'http://google.com' }
|
let(:text) { 'http://google.com' }
|
||||||
|
|
||||||
it 'matches the full URL' do
|
it 'matches the full URL' do
|
||||||
@ -280,6 +280,26 @@ RSpec.describe TextFormatter do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when given a lengthy URL' do
|
||||||
|
let(:text) { 'lorem https://prepitaph.org/wip/web-dovespair/ ipsum' }
|
||||||
|
|
||||||
|
it 'truncates the URL' do
|
||||||
|
expect(subject).to include '<span class="invisible">https://</span>'
|
||||||
|
expect(subject).to include '<span class="ellipsis">prepitaph.org/wip/web-dovespai</span>'
|
||||||
|
expect(subject).to include '<span class="invisible">r/</span>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when given a sufficiently short URL' do
|
||||||
|
let(:text) { 'lorem https://prepitaph.org/wip/web-devspair/ ipsum' }
|
||||||
|
|
||||||
|
it 'does not truncate the URL' do
|
||||||
|
expect(subject).to include '<span class="invisible">https://</span>'
|
||||||
|
expect(subject).to include '<span class="">prepitaph.org/wip/web-devspair/</span>'
|
||||||
|
expect(subject).to include '<span class="invisible"></span>'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when given text containing a hashtag' do
|
context 'when given text containing a hashtag' do
|
||||||
let(:text) { '#hashtag' }
|
let(:text) { '#hashtag' }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user