Problem
Rack::Request#host returns unexpected host when the domain starts with a number.
Rack v2.1.2 returns host correctly.
gem 'rack', '2.1.2'
require 'rack'
p Rack::Request.new({'HTTP_HOST' => '123foo.example.com'}).host
# => "123foo.example.com"
But Rack v2.2.0 (and v2.2.1) returns a part of the host unexpectedly.
gem 'rack', '2.2.0'
require 'rack'
p Rack::Request.new({'HTTP_HOST' => '123foo.example.com'}).host
# => "123"
I guess the cause is the following pull request. #1561
|
AUTHORITY = / |
|
# The host: |
|
(?<host> |
|
# An IPv6 address: |
|
(\[(?<ip6>.*)\]) |
|
| |
|
# An IPv4 address: |
|
(?<ip4>[\d\.]+) |
|
| |
|
# A hostname: |
|
(?<name>[a-zA-Z0-9\.\-]+) |
|
) |
|
# The optional port: |
|
(:(?<port>\d+))? |
|
/x |
The
AUTHORITY regexp looks too loose.
123 matches as an
ip4, but it is not an ip4.
Problem
Rack::Request#hostreturns unexpected host when the domain starts with a number.Rack v2.1.2 returns host correctly.
But Rack v2.2.0 (and v2.2.1) returns a part of the host unexpectedly.
I guess the cause is the following pull request. #1561
rack/lib/rack/request.rb
Lines 601 to 615 in 838ce3a
The
AUTHORITYregexp looks too loose.123matches as anip4, but it is not an ip4.