diff --git a/lib/rack/request.rb b/lib/rack/request.rb index be8f0b3bf..750a0dc44 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -598,7 +598,7 @@ def split_header(value) value ? value.strip.split(/[,\s]+/) : [] end - AUTHORITY = / + AUTHORITY = /^ # The host: (? # An IPv6 address: @@ -612,7 +612,7 @@ def split_header(value) ) # The optional port: (:(?\d+))? - /x + $/x private_constant :AUTHORITY diff --git a/test/spec_request.rb b/test/spec_request.rb index 4e6e52d63..f3eaae934 100644 --- a/test/spec_request.rb +++ b/test/spec_request.rb @@ -116,6 +116,11 @@ class RackRequestTest < Minitest::Spec req.host.must_equal "www2.example.org" req.hostname.must_equal "www2.example.org" + req = make_request \ + Rack::MockRequest.env_for("/", "HTTP_HOST" => "123foo.example.com") + req.host.must_equal "123foo.example.com" + req.hostname.must_equal "123foo.example.com" + req = make_request \ Rack::MockRequest.env_for("/", "SERVER_NAME" => "example.org", "SERVER_PORT" => "9292") req.host.must_equal "example.org"