Browse files

Make sure that rails recognized the full notation of IPv6 loopback ad…

…dress, and recognize 127.0.0.0/8 in IPv4

[#3257 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent ed8cabc commit 0f44d37d04063bdae12c48e85f34024775c6a9f9 @sikachu sikachu committed with josevalim Jun 6, 2010
Showing with 7 additions and 8 deletions.
  1. +2 −2 actionpack/lib/action_controller/rescue.rb
  2. +5 −6 actionpack/test/controller/rescue_test.rb
View
4 actionpack/lib/action_controller/rescue.rb
@@ -15,7 +15,7 @@ module ActionController #:nodoc:
# behavior is achieved by overriding the <tt>rescue_action_in_public</tt>
# and <tt>rescue_action_locally</tt> methods.
module Rescue
- LOCALHOST = ['127.0.0.1', '::1'].freeze
+ LOCALHOST = [/^127\.0\.0\.\d{1,3}$/, /^::1$/, /^0:0:0:0:0:0:0:1(%.*)?$/].freeze
DEFAULT_RESCUE_RESPONSE = :internal_server_error
DEFAULT_RESCUE_RESPONSES = {
@@ -122,7 +122,7 @@ def render_optional_error_file(status_code)
# method if you wish to redefine the meaning of a local request to
# include remote IP addresses or other criteria.
def local_request? #:doc:
- LOCALHOST.any?{ |local_ip| request.remote_addr == local_ip && request.remote_ip == local_ip }
+ LOCALHOST.any?{ |local_ip| request.remote_addr =~ local_ip && request.remote_ip =~ local_ip }
end
# Render detailed diagnostics for unhandled exceptions rescued from
View
11 actionpack/test/controller/rescue_test.rb
@@ -281,12 +281,11 @@ def test_rescue_action_locally
end
def test_local_request_when_remote_addr_is_localhost
- @controller.expects(:request).returns(@request).at_least(4)
- with_remote_addr '127.0.0.1' do
- assert @controller.send(:local_request?)
- end
- with_remote_addr '::1' do
- assert @controller.send(:local_request?)
+ @controller.expects(:request).returns(@request).at_least(10)
+ ['127.0.0.1', '127.0.0.127', '::1', '0:0:0:0:0:0:0:1', '0:0:0:0:0:0:0:1%0'].each do |ip_address|
+ with_remote_addr ip_address do
+ assert @controller.send(:local_request?)
+ end
end
end

0 comments on commit 0f44d37

Please sign in to comment.