commit: 039e6f951ca16bd4183fb29d782dd095d2b4120a
parent: 882c94a6bf825fb125ed3229db8653d076f1d774
Author: Eugen Rochko <eugen@zeonfederated.com>
Date: Sun, 27 Mar 2016 23:38:46 +0200
Fix issue with unresolvable usernames
Diffstat:
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git 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}<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
diff --git 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('<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