FIX: category slug route was not working for subfolder setup

https://meta.discourse.org/t/relative-url-root-issues-incorrect-latest-link-incorrect-redirect/163266

URLs like `/forum/c/staff` (subfolder setup) were landing on
`/forum/forum/c/staff/3`. Note the extra "/forum". This commit
strips the redundant subfolder path from category URL.
This commit is contained in:
Arpit Jalan 2020-09-11 22:43:10 +05:30
parent ddcf0d7d01
commit 32d6286bea
2 changed files with 13 additions and 1 deletions

View File

@ -372,6 +372,10 @@ class ListController < ApplicationController
if current_slug != real_slug if current_slug != real_slug
url = request.fullpath.gsub(current_slug, real_slug) url = request.fullpath.gsub(current_slug, real_slug)
if ActionController::Base.config.relative_url_root
url = url.sub(ActionController::Base.config.relative_url_root, "")
end
return redirect_to path(url), status: 301 return redirect_to path(url), status: 301
end end

View File

@ -729,7 +729,15 @@ RSpec.describe ListController do
end end
context "with subfolder" do context "with subfolder" do
it "redirects to URL containing the updated slug" do it "main category redirects to URL containing the updated slug" do
set_subfolder "/forum"
get "/c/#{category.slug}"
expect(response.status).to eq(301)
expect(response).to redirect_to("/forum/c/#{category.slug}/#{category.id}")
end
it "sub-sub-category redirects to URL containing the updated slug" do
set_subfolder "/forum" set_subfolder "/forum"
get "/c/hello/world/bye/#{subsubcategory.id}" get "/c/hello/world/bye/#{subsubcategory.id}"