File tree Expand file tree Collapse file tree 3 files changed +20
-2
lines changed
Expand file tree Collapse file tree 3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,18 @@ def self.build(args)
6161 super ( tmp )
6262 end
6363
64+ # Do not allow empty host names, as they are not allowed by RFC 3986.
65+ def check_host ( v )
66+ ret = super
67+
68+ if ret && v . empty?
69+ raise InvalidComponentError ,
70+ "bad component(expected host component): #{ v } "
71+ end
72+
73+ ret
74+ end
75+
6476 #
6577 # == Description
6678 #
Original file line number Diff line number Diff line change @@ -846,8 +846,10 @@ def test_ipv6
846846 assert_equal ( "http://[::1]/bar" , u . to_s )
847847 u . hostname = "::1"
848848 assert_equal ( "http://[::1]/bar" , u . to_s )
849- u . hostname = ""
850- assert_equal ( "http:///bar" , u . to_s )
849+
850+ u = URI ( "file://foo/bar" )
851+ u . hostname = ''
852+ assert_equal ( "file:///bar" , u . to_s )
851853 end
852854
853855 def test_build
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ def test_build
1919 assert_kind_of ( URI ::HTTP , u )
2020 end
2121
22+ def test_build_empty_host
23+ assert_raise ( URI ::InvalidComponentError ) { URI ::HTTP . build ( host : '' ) }
24+ end
25+
2226 def test_parse
2327 u = URI . parse ( 'http://a' )
2428 assert_kind_of ( URI ::HTTP , u )
You can’t perform that action at this time.
0 commit comments