Skip to content
Snippets Groups Projects
Commit 039e6f95 authored by Eugen Rochko's avatar Eugen Rochko
Browse files

Fix issue with unresolvable usernames

parent 882c94a6
No related branches found
No related tags found
No related merge requests found
......@@ -38,8 +38,11 @@ module ApplicationHelper
def linkify(status)
auto_link(HTMLEntities.new.encode(status.text), link: :urls, html: { rel: 'nofollow noopener' }).gsub(Account::MENTION_RE) do |m|
account = account_from_mentions(Account::MENTION_RE.match(m)[1], status.mentions)
"#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>"
if account = account_from_mentions(Account::MENTION_RE.match(m)[1], status.mentions)
"#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>"
else
m
end
end.html_safe
end
......
......@@ -44,6 +44,11 @@ RSpec.describe ApplicationHelper, type: :helper do
status.mentions.create(account: alice)
expect(helper.linkify(status)).to match('<a href="http://test.host/users/alice" class="mention">@<span>alice</span></a>')
end
it 'leaves mention of unresolvable user alone' do
status = Fabricate(:status, text: 'Hello @foo', account: bob)
expect(helper.linkify(status)).to match('Hello @foo')
end
end
describe '#account_from_mentions' do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment