FIX: handle array in redirect param

This commit is contained in:
Arpit Jalan 2019-06-11 17:10:16 +05:30
parent f4fd75aea4
commit e2636f0ec7
2 changed files with 10 additions and 2 deletions

View File

@ -89,10 +89,11 @@ class StaticController < ApplicationController
destination = path("/")
if params[:redirect].present? && !params[:redirect].match(login_path)
redirect_location = params[:redirect].to_s
if redirect_location.present? && !redirect_location.match(login_path)
begin
forum_uri = URI(Discourse.base_url)
uri = URI(params[:redirect])
uri = URI(redirect_location)
if uri.path.present? &&
(uri.host.blank? || uri.host == forum_uri.host) &&

View File

@ -283,6 +283,13 @@ describe StaticController do
end
end
context 'with an array' do
it "redirects to the root" do
post "/login.json", params: { redirect: ["/foo"] }
expect(response).to redirect_to('/')
end
end
context 'when the redirect path is the login page' do
it 'redirects to the root url' do
post "/login.json", params: { redirect: login_path }