Skip to content

Commit

Permalink
Fix mastodon#690 - Webfinger should handle new shortform profile URLs…
Browse files Browse the repository at this point in the history
… now (nice)
  • Loading branch information
Gargron committed Mar 28, 2017
1 parent 448a07c commit 1c6b02f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions app/controllers/xrd_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ def set_default_format_json
end

def username_from_resource
if resource_param.start_with?('acct:') || resource_param.include?('@')
resource_param.split('@').first.gsub('acct:', '')
if resource_param =~ /\Ahttps?:\/\//
path_params = Rails.application.routes.recognize_path(resource_param)
raise ActiveRecord::RecordNotFound unless path_params[:controller] == 'users' && path_params[:action] == 'show'
path_params[:username]
else
url = Addressable::URI.parse(resource_param)
url.path.gsub('/users/', '')
username, domain = resource_param.gsub(/\Aacct:/, '').split('@')
raise ActiveRecord::RecordNotFound unless TagManager.instance.local_domain?(domain)
username
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/api/v1/accounts/show.rabl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
object @account

attributes :id, :username, :acct, :display_name, :locked
attributes :id, :username, :acct, :display_name, :locked, :created_at

node(:note) { |account| Formatter.instance.simplified_format(account) }
node(:url) { |account| TagManager.instance.url_for(account) }
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/xrd_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let(:alice) { Fabricate(:account, username: 'alice') }

it 'returns http success when account can be found' do
get :webfinger, params: { resource: "acct:#{alice.username}@anything.com" }
get :webfinger, params: { resource: "acct:#{alice.username}@#{Rails.configuration.x.local_domain}" }
expect(response).to have_http_status(:success)
end

Expand Down

0 comments on commit 1c6b02f

Please sign in to comment.