discourse/plugins/discourse-post-voting/spec/requests
Régis Hanol 0a2a6b4871
FIX: Redirect over-range topic page URLs instead of 404 (#40224)
Requesting `/t/slug/id?page=N` with a page number beyond the topic's
last valid page raised `Discourse::NotFound` and returned 404. This
produced a long-running stream of "increase in 404 errors" reports in
Google Search Console, because crawlers (and our own
`sitemap_recent.xml`) hold cached page URLs that become stale when a
topic shrinks — most often after deleted posts or topic splits.

The 404 also masked a latent bug for staff: the original check compared
the requested page against `topic.posts_count`, a cached column that
excludes whispers and ignores active filters (`username_filters`,
`replies_to_post_number`, etc.). A staff user navigating to `?page=N`
covering whisper posts could be 404'd even though the page contained
content they were entitled to see.

Replace the 404 with a 301 redirect to the last valid page (or the
unparameterized topic URL if the topic fits in one page), using
`@topic_view.filtered_posts.count` — the count of posts visible to the
current viewer — so the math respects whispers, deletions visible to
staff, and active filters. The COUNT query is gated behind `page > 1` so
the common case (no `?page=` param) pays nothing extra.

Negative pages still raise 404; only the over-range case becomes a
redirect.

https://meta.discourse.org/t/96337
2026-05-22 18:48:59 +02:00
..
post_voting FIX: Full names are exposed when name display is disabled (#39838) 2026-05-11 08:34:43 +10:00
list_controller_spec.rb
posts_controller_spec.rb FIX: update post voting for new JSON encoding (#39206) 2026-04-14 11:55:27 -05:00
topics_controller_spec.rb FIX: Redirect over-range topic page URLs instead of 404 (#40224) 2026-05-22 18:48:59 +02:00