mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
FIX: Render a 404 error on a bad redirect in list controller
When bad data is provided in the URI for redirecting to a category, Rails raises an `ActionController::Redirecting::UnsafeRedirectError` error, leading to a 500 error. This patch catches the exception to render a 404 instead.
This commit is contained in:

committed by
Loïc Guitaut

parent
a442eeb0f4
commit
232503b3df
@ -49,6 +49,10 @@ class ListController < ApplicationController
|
|||||||
:filter,
|
:filter,
|
||||||
].flatten
|
].flatten
|
||||||
|
|
||||||
|
rescue_from ActionController::Redirecting::UnsafeRedirectError do
|
||||||
|
raise Discourse::NotFound
|
||||||
|
end
|
||||||
|
|
||||||
# Create our filters
|
# Create our filters
|
||||||
Discourse.filters.each do |filter|
|
Discourse.filters.each do |filter|
|
||||||
define_method(filter) do |options = nil|
|
define_method(filter) do |options = nil|
|
||||||
|
@ -1124,6 +1124,20 @@ RSpec.describe ListController do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when redirect raises an unsafe redirect error" do
|
||||||
|
before do
|
||||||
|
ListController
|
||||||
|
.any_instance
|
||||||
|
.stubs(:redirect_to)
|
||||||
|
.raises(ActionController::Redirecting::UnsafeRedirectError)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders a 404" do
|
||||||
|
get "/c/hello/world/bye/#{subsubcategory.id}"
|
||||||
|
expect(response).to have_http_status :not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "shared drafts" do
|
describe "shared drafts" do
|
||||||
|
Reference in New Issue
Block a user