FIX: Don't error out on nested categories index page param (#29273)

We're expecting the page param to be something that neatly coerces into an integer. If we receive something like a nested parameter, this will blow up. (I'm sure there are other examples as well.)

This commit falls back to a page value of 1 if the coercion fails.
This commit is contained in:
Ted Johansson 2024-10-18 14:37:39 +08:00 committed by GitHub
parent 48308a5ee6
commit 9dafbe47dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -620,7 +620,7 @@ class CategoriesController < ApplicationController
include_topics: include_topics,
include_subcategories: include_subcategories,
tag: params[:tag],
page: params[:page].to_i,
page: params[:page].try(:to_i) || 1,
}
@category_list = CategoryList.new(guardian, category_options)

View File

@ -425,6 +425,11 @@ RSpec.describe CategoriesController do
expect(response.status).to eq(200)
expect(response.parsed_body["category_list"]["categories"].count).to eq(0)
end
it "does not error out if page is a nested parameter" do
get "/categories.json?page[foo]=2"
expect(response.status).to eq(200)
end
end
end