Unescape back_url param before calling redirect_to.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1893 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e1c4659752
commit
8a356baf3e
|
@ -16,6 +16,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
layout 'base'
|
layout 'base'
|
||||||
|
@ -123,7 +124,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_back_or_default(default)
|
def redirect_back_or_default(default)
|
||||||
back_url = params[:back_url]
|
back_url = CGI.unescape(params[:back_url].to_s)
|
||||||
if !back_url.blank?
|
if !back_url.blank?
|
||||||
uri = URI.parse(back_url)
|
uri = URI.parse(back_url)
|
||||||
# do not redirect user to another host
|
# do not redirect user to another host
|
||||||
|
|
|
@ -194,7 +194,7 @@ class TimelogController < ApplicationController
|
||||||
@time_entry.attributes = params[:time_entry]
|
@time_entry.attributes = params[:time_entry]
|
||||||
if request.post? and @time_entry.save
|
if request.post? and @time_entry.save
|
||||||
flash[:notice] = l(:notice_successful_update)
|
flash[:notice] = l(:notice_successful_update)
|
||||||
redirect_to(params[:back_url].blank? ? {:action => 'details', :project_id => @time_entry.project} : params[:back_url])
|
redirect_back_or_default :action => 'details', :project_id => @time_entry.project
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,12 +46,12 @@ class AccountControllerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_login_should_redirect_to_back_url_param
|
def test_login_should_redirect_to_back_url_param
|
||||||
# request.uri is "test.host" in test environment
|
# request.uri is "test.host" in test environment
|
||||||
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
|
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.host%2Fissues%2Fshow%2F1'
|
||||||
assert_redirected_to '/issues/show/1'
|
assert_redirected_to '/issues/show/1'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_login_should_not_redirect_to_another_host
|
def test_login_should_not_redirect_to_another_host
|
||||||
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake'
|
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http%3A%2F%2Ftest.foo%2Ffake'
|
||||||
assert_redirected_to '/my/page'
|
assert_redirected_to '/my/page'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue