Ensure multiple leading / are also removed, thanks @homakov

This commit is contained in:
José Valim 2013-11-13 15:01:23 +01:00
parent 3b598ec235
commit f36efc0cc9
2 changed files with 3 additions and 2 deletions

View File

@ -33,7 +33,7 @@ module Devise
# #
def store_location_for(resource_or_scope, location) def store_location_for(resource_or_scope, location)
session_key = stored_location_key_for(resource_or_scope) session_key = stored_location_key_for(resource_or_scope)
session[session_key] = URI.parse(location).path if location session[session_key] = URI.parse(location).path.sub(/\A\/+/, '/') if location
end end
private private

View File

@ -199,9 +199,10 @@ class ControllerAuthenticatableTest < ActionController::TestCase
end end
test 'store location for stores only paths' do test 'store location for stores only paths' do
assert_nil @controller.stored_location_for(:user)
@controller.store_location_for(:user, "//host/foo.bar") @controller.store_location_for(:user, "//host/foo.bar")
assert_equal "/foo.bar", @controller.stored_location_for(:user) assert_equal "/foo.bar", @controller.stored_location_for(:user)
@controller.store_location_for(:user, "///foo.bar")
assert_equal "/foo.bar", @controller.stored_location_for(:user)
end end
test 'after sign in path defaults to root path if none by was specified for the given scope' do test 'after sign in path defaults to root path if none by was specified for the given scope' do