Skip to content

Commit

Permalink
Fix search params being dropped when redirected to non-deck path (mas…
Browse files Browse the repository at this point in the history
  • Loading branch information
renchap authored Sep 25, 2024
1 parent 83574f6 commit 3dc4ddc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/web_app_controller_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def set_app_body_class
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?
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/features/ui/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class SwitchingColumnsArea extends PureComponent {
{redirect}

{singleColumn ? <Redirect from='/deck' to='/home' exact /> : null}
{singleColumn && pathName.startsWith('/deck/') ? <Redirect from={pathName} to={pathName.slice(5)} /> : null}
{singleColumn && pathName.startsWith('/deck/') ? <Redirect from={pathName} to={{...this.props.location, pathname: pathName.slice(5)}} /> : null}
{/* Redirect old bookmarks (without /deck) with home-like routes to the advanced interface */}
{!singleColumn && pathName === '/getting-started' ? <Redirect from='/getting-started' to='/deck/getting-started' exact /> : null}
{!singleColumn && pathName === '/home' ? <Redirect from='/home' to='/deck/getting-started' exact /> : null}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/permalink_redirector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ def second_segment
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
15 changes: 15 additions & 0 deletions spec/lib/permalink_redirector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,20 @@
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

0 comments on commit 3dc4ddc

Please sign in to comment.