DEV: Add proper error response when searching with an invalid page param (#31026)

Previously, for a search query with `page=11` or higher, we were quietly
returning the page 10 results. The frontend app isn't affected because
it sets its own limit to 10 pages, but still, this response from the
search endpoint does not make sense.

This change switches to returning a 400 error when the `page` parameter
is above the allowed limit (a max of 10).
This commit is contained in:
Penar Musaraj
2025-01-28 15:12:52 -05:00
committed by GitHub
parent 7334cfb191
commit dcac09ed32
2 changed files with 11 additions and 1 deletions

View File

@@ -348,6 +348,11 @@ RSpec.describe SearchController do
expect(response.status).to eq(400)
end
it "returns a 400 error if the page parameter is above the limit" do
get "/search.json", params: { q: "kittens", page: 11 }
expect(response.status).to eq(400)
end
it "logs the search term" do
SiteSetting.log_search_queries = true
get "/search.json", params: { q: "bantha" }