From 3dc4ddc6631585813c1c5bce9e8679f101a03a56 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Wed, 25 Sep 2024 15:35:37 +0200 Subject: [PATCH] Fix search params being dropped when redirected to non-deck path (#31984) --- .../concerns/web_app_controller_concern.rb | 2 +- app/javascript/mastodon/features/ui/index.jsx | 2 +- app/lib/permalink_redirector.rb | 2 +- spec/lib/permalink_redirector_spec.rb | 15 +++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/web_app_controller_concern.rb b/app/controllers/concerns/web_app_controller_concern.rb index e1f599dcb..ebbdba59a 100644 --- a/app/controllers/concerns/web_app_controller_concern.rb +++ b/app/controllers/concerns/web_app_controller_concern.rb @@ -31,7 +31,7 @@ module WebAppControllerConcern def redirect_unauthenticated_to_permalinks! return if user_signed_in? && current_account.moved_to_account_id.nil? - permalink_redirector = PermalinkRedirector.new(request.path) + permalink_redirector = PermalinkRedirector.new(request.original_fullpath) return if permalink_redirector.redirect_path.blank? expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in? diff --git a/app/javascript/mastodon/features/ui/index.jsx b/app/javascript/mastodon/features/ui/index.jsx index a6e364047..2f9f962b8 100644 --- a/app/javascript/mastodon/features/ui/index.jsx +++ b/app/javascript/mastodon/features/ui/index.jsx @@ -186,7 +186,7 @@ class SwitchingColumnsArea extends PureComponent { {redirect} {singleColumn ? : null} - {singleColumn && pathName.startsWith('/deck/') ? : null} + {singleColumn && pathName.startsWith('/deck/') ? : null} {/* Redirect old bookmarks (without /deck) with home-like routes to the advanced interface */} {!singleColumn && pathName === '/getting-started' ? : null} {!singleColumn && pathName === '/home' ? : null} diff --git a/app/lib/permalink_redirector.rb b/app/lib/permalink_redirector.rb index f551f69db..142a05d10 100644 --- a/app/lib/permalink_redirector.rb +++ b/app/lib/permalink_redirector.rb @@ -83,6 +83,6 @@ class PermalinkRedirector end def path_segments - @path_segments ||= @path.delete_prefix('/deck').delete_prefix('/').split('/') + @path_segments ||= @path.split('?')[0].delete_prefix('/deck').delete_prefix('/').split('/') end end diff --git a/spec/lib/permalink_redirector_spec.rb b/spec/lib/permalink_redirector_spec.rb index 3f77d7665..5a544c3d3 100644 --- a/spec/lib/permalink_redirector_spec.rb +++ b/spec/lib/permalink_redirector_spec.rb @@ -29,5 +29,20 @@ RSpec.describe PermalinkRedirector do redirector = described_class.new('@alice/123') expect(redirector.redirect_path).to eq 'https://example.com/status-123' end + + it 'returns path for legacy status links with a query param' do + redirector = described_class.new('statuses/123?foo=bar') + expect(redirector.redirect_path).to eq 'https://example.com/status-123' + end + + it 'returns path for pretty status links with a query param' do + redirector = described_class.new('@alice/123?foo=bar') + expect(redirector.redirect_path).to eq 'https://example.com/status-123' + end + + it 'returns path for deck URLs with query params' do + redirector = described_class.new('/deck/directory?local=true') + expect(redirector.redirect_path).to eq '/directory?local=true' + end end end