diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index a56bbe59e89..e2baecede64 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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}@#{account.acct}"
+ if account = account_from_mentions(Account::MENTION_RE.match(m)[1], status.mentions)
+ "#{m.split('@').first}@#{account.acct}"
+ else
+ m
+ end
end.html_safe
end
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 30b3653ee04..d294b9587ba 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -44,6 +44,11 @@ RSpec.describe ApplicationHelper, type: :helper do
status.mentions.create(account: alice)
expect(helper.linkify(status)).to match('@alice')
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