Redirect to short account URLs when requesting HTML for one of the AP endpoints (#38056)

This commit is contained in:
Claire
2026-03-04 18:44:27 +01:00
committed by GitHub
parent a70079968c
commit 1add29cf40
3 changed files with 17 additions and 3 deletions

View File

@@ -18,6 +18,8 @@ class AccountsController < ApplicationController
respond_to do |format|
format.html do
expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.hour) unless user_signed_in?
redirect_to short_account_path(@account) if account_id_param.present? && username_param.blank?
end
format.rss do

View File

@@ -26,6 +26,8 @@ class StatusesController < ApplicationController
respond_to do |format|
format.html do
expires_in 10.seconds, public: true if current_account.nil?
redirect_to short_account_status_path(@account, @status) if account_id_param.present? && username_param.blank?
end
format.json do

View File

@@ -6,10 +6,20 @@ RSpec.describe 'Accounts show response' do
let(:account) { Fabricate(:account) }
context 'with numeric-based identifiers' do
it 'returns http success' do
get "/ap/users/#{account.id}"
context 'with JSON format' do
it 'returns http success' do
get "/ap/users/#{account.id}", headers: { 'ACCEPT' => 'application/json' }
expect(response).to have_http_status(200)
expect(response).to have_http_status(200)
end
end
context 'with HTML format' do
it 'redirects to success' do
get "/ap/users/#{account.id}", as: 'html'
expect(response).to redirect_to("/@#{account.username}")
end
end
end