FIX: Category redirect to correct slug should not loop (#11772)

The server responds with a redirect to URLs with wrong slugs, even when
the slug was the correct but in the encoded form (if it contained
special characters).
This commit is contained in:
Bianca Nenciu
2021-02-16 17:54:50 +02:00
committed by GitHub
parent d89c5aedbe
commit fa3eb1f7fc
2 changed files with 32 additions and 1 deletions

View File

@ -759,6 +759,37 @@ RSpec.describe ListController do
get "/c/hello/world/bye/#{subsubcategory.id}"
expect(response.status).to eq(301)
expect(response).to redirect_to("/c/#{category.slug}/#{subcategory.slug}/#{subsubcategory.slug}/#{subsubcategory.id}")
get "/c/#{category.slug}/#{subcategory.slug}/#{subsubcategory.slug}/#{subsubcategory.id}"
expect(response.status).to eq(200)
end
it "redirects to URL with correct case slug" do
category.update!(slug: "hello")
get "/c/Hello/#{category.id}"
expect(response).to redirect_to("/c/hello/#{category.id}")
get "/c/hello/#{category.id}"
expect(response.status).to eq(200)
end
context "does not create a redirect loop" do
it "with encoded slugs" do
category = Fabricate(:category)
category.update_columns(slug: CGI.escape("systèmes"))
get "/c/syst%C3%A8mes/#{category.id}"
expect(response.status).to eq(200)
end
it "with lowercase encoded slugs" do
category = Fabricate(:category)
category.update_columns(slug: CGI.escape("systèmes").downcase)
get "/c/syst%C3%A8mes/#{category.id}"
expect(response.status).to eq(200)
end
end
context "with subfolder" do