A platform for community discussion. Free, open, simple.
FIX: handle redirect issue with categoryId rewriting page number (#33009)
Suvodhoy Sinhaf0e72f620618
diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rbindex e28a8ee5cbf..0de3afb3094 100644--- a/app/controllers/list_controller.rb+++ b/app/controllers/list_controller.rb@@ -422,7 +422,10 @@ class ListController < ApplicationControllerendreal_slug = @category.full_slug("/")if CGI.unescape(current_slug) != CGI.unescape(real_slug)- url = CGI.unescape(request.fullpath).gsub(current_slug, real_slug)+ path = CGI.unescape(request.path)+ query = request.query_string+ new_path = path.gsub(current_slug, real_slug)+ url = query.present? ? "#{new_path}?#{query}" : new_pathif ActionController::Base.config.relative_url_rooturl = url.sub(ActionController::Base.config.relative_url_root, "")enddiff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex dcccee56870..833f994d2ed 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -1208,6 +1208,13 @@ RSpec.describe ListController doexpect(response.status).to eq(200)end+ it "redirects to the canonical slug without altering query parameters" do+ # Simulate a request with just the category ID in the path, and a query param that matches the ID+ get "/c/#{category.id}.json?page=#{category.id}"+ expect(response.status).to eq(301)+ expect(response).to redirect_to("/c/#{category.slug}/#{category.id}.json?page=#{category.id}")+ end+it "redirects to URL with correct case slug" docategory.update!(slug: "hello")