mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
[ruby/uri] Do not allow empty host names, as they are not allowed by RFC 3986
Pointed out by John Hawthorn. Fixes [Bug #20686] https://github.com/ruby/uri/commit/c0cfa04a66
This commit is contained in:
parent
1add45e2a6
commit
22b81b5bf5
@ -61,6 +61,18 @@ module URI
|
||||
super(tmp)
|
||||
end
|
||||
|
||||
# Do not allow empty host names, as they are not allowed by RFC 3986.
|
||||
def check_host(v)
|
||||
ret = super
|
||||
|
||||
if ret && v.empty?
|
||||
raise InvalidComponentError,
|
||||
"bad component(expected host component): #{v}"
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
|
||||
#
|
||||
# == Description
|
||||
#
|
||||
|
||||
@ -846,8 +846,10 @@ class URI::TestGeneric < Test::Unit::TestCase
|
||||
assert_equal("http://[::1]/bar", u.to_s)
|
||||
u.hostname = "::1"
|
||||
assert_equal("http://[::1]/bar", u.to_s)
|
||||
u.hostname = ""
|
||||
assert_equal("http:///bar", u.to_s)
|
||||
|
||||
u = URI("file://foo/bar")
|
||||
u.hostname = ''
|
||||
assert_equal("file:///bar", u.to_s)
|
||||
end
|
||||
|
||||
def test_build
|
||||
|
||||
@ -19,6 +19,10 @@ class URI::TestHTTP < Test::Unit::TestCase
|
||||
assert_kind_of(URI::HTTP, u)
|
||||
end
|
||||
|
||||
def test_build_empty_host
|
||||
assert_raise(URI::InvalidComponentError) { URI::HTTP.build(host: '') }
|
||||
end
|
||||
|
||||
def test_parse
|
||||
u = URI.parse('http://a')
|
||||
assert_kind_of(URI::HTTP, u)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user