Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/uri/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ def self.build(args)
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
#
Expand Down
6 changes: 4 additions & 2 deletions test/uri/test_generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,10 @@ def test_ipv6
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
Expand Down
4 changes: 4 additions & 0 deletions test/uri/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def test_build
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)
Expand Down