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)
61
61
super ( tmp )
62
62
end
63
63
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
+
64
76
#
65
77
# == Description
66
78
#
Original file line number Diff line number Diff line change @@ -846,8 +846,10 @@ def test_ipv6
846
846
assert_equal ( "http://[::1]/bar" , u . to_s )
847
847
u . hostname = "::1"
848
848
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 )
851
853
end
852
854
853
855
def test_build
Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ def test_build
19
19
assert_kind_of ( URI ::HTTP , u )
20
20
end
21
21
22
+ def test_build_empty_host
23
+ assert_raise ( URI ::InvalidComponentError ) { URI ::HTTP . build ( host : '' ) }
24
+ end
25
+
22
26
def test_parse
23
27
u = URI . parse ( 'http://a' )
24
28
assert_kind_of ( URI ::HTTP , u )
You can’t perform that action at this time.
0 commit comments