Fix HTTP 200 response code on paths to remote accounts that don't exist

This commit is contained in:
Eugen Rochko
2026-08-31 18:40:53 +02:00
parent cd3c540957
commit 5bb0e17516
4 changed files with 22 additions and 10 deletions

View File

@@ -0,0 +1,12 @@
# frozen_string_literal: true
class RemoteAccountsController < HomeController
before_action :require_resource_exists!
private
def require_resource_exists!
# The page should still render normally, but the HTTP code should be modified
response.status = 404 if PermalinkRedirector.new(request.original_fullpath).object.nil?
end
end

View File

@@ -103,7 +103,7 @@ class ResolveURLService < BaseService
return unless recognized_params[:action] == 'show'
Account.find_local(recognized_params[:username])
when 'home'
when 'home', 'remote_accounts'
return unless recognized_params[:action] == 'index' && recognized_params[:username_with_domain].present?
if recognized_params[:any]&.match?(/\A[0-9]+\Z/)

View File

@@ -176,7 +176,7 @@ Rails.application.routes.draw do
get '/@:account_username/wrapstodon/:year/:share_key', to: 'wrapstodon#show', as: :public_wrapstodon
end
get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
get '/@:username_with_domain/(*any)', to: 'remote_accounts#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
get '/settings', to: redirect('/settings/profile')
draw(:settings)

View File

@@ -107,35 +107,35 @@ RSpec.describe 'Routes under accounts/' do
let(:username) { 'alice@example.com' }
it 'routes /@:username' do
expect(get("/@#{username}")).to route_to('home#index', username_with_domain: username)
expect(get("/@#{username}")).to route_to('remote_accounts#index', username_with_domain: username)
end
it 'routes /@:username/:id' do
expect(get("/@#{username}/123")).to route_to('home#index', username_with_domain: username, any: '123')
expect(get("/@#{username}/123")).to route_to('remote_accounts#index', username_with_domain: username, any: '123')
end
it 'routes /@:username/:id/embed' do
expect(get("/@#{username}/123/embed")).to route_to('home#index', username_with_domain: username, any: '123/embed')
expect(get("/@#{username}/123/embed")).to route_to('remote_accounts#index', username_with_domain: username, any: '123/embed')
end
it 'routes /@:username/following' do
expect(get("/@#{username}/following")).to route_to('home#index', username_with_domain: username, any: 'following')
expect(get("/@#{username}/following")).to route_to('remote_accounts#index', username_with_domain: username, any: 'following')
end
it 'routes /@:username/followers' do
expect(get("/@#{username}/followers")).to route_to('home#index', username_with_domain: username, any: 'followers')
expect(get("/@#{username}/followers")).to route_to('remote_accounts#index', username_with_domain: username, any: 'followers')
end
it 'routes /@:username/with_replies' do
expect(get("/@#{username}/with_replies")).to route_to('home#index', username_with_domain: username, any: 'with_replies')
expect(get("/@#{username}/with_replies")).to route_to('remote_accounts#index', username_with_domain: username, any: 'with_replies')
end
it 'routes /@:username/media' do
expect(get("/@#{username}/media")).to route_to('home#index', username_with_domain: username, any: 'media')
expect(get("/@#{username}/media")).to route_to('remote_accounts#index', username_with_domain: username, any: 'media')
end
it 'routes /@:username/tagged/:tag' do
expect(get("/@#{username}/tagged/foo")).to route_to('home#index', username_with_domain: username, any: 'tagged/foo')
expect(get("/@#{username}/tagged/foo")).to route_to('remote_accounts#index', username_with_domain: username, any: 'tagged/foo')
end
end