File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -643,7 +643,7 @@ def host=(v)
643
643
#
644
644
def hostname
645
645
v = self . host
646
- / \A \[ (.*) \] \z / =~ v ? $1 : v
646
+ v &. start_with? ( '[' ) && v . end_with? ( ']' ) ? v [ 1 ..- 2 ] : v
647
647
end
648
648
649
649
# Sets the host part of the URI as the argument with brackets for IPv6 addresses.
@@ -659,7 +659,7 @@ def hostname
659
659
# it is wrapped with brackets.
660
660
#
661
661
def hostname = ( v )
662
- v = "[#{ v } ]" if / \A \[ .* \] \z / !~ v && /:/ =~ v
662
+ v = "[#{ v } ]" if ! ( v &. start_with? ( '[' ) && v &. end_with? ( ']' ) ) && v &. index ( ':' )
663
663
self . host = v
664
664
end
665
665
Original file line number Diff line number Diff line change @@ -799,8 +799,12 @@ def test_ipv6
799
799
800
800
u = URI ( "http://foo/bar" )
801
801
assert_equal ( "http://foo/bar" , u . to_s )
802
+ u . hostname = "[::1]"
803
+ assert_equal ( "http://[::1]/bar" , u . to_s )
802
804
u . hostname = "::1"
803
805
assert_equal ( "http://[::1]/bar" , u . to_s )
806
+ u . hostname = ""
807
+ assert_equal ( "http:///bar" , u . to_s )
804
808
end
805
809
806
810
def test_build
You can’t perform that action at this time.
0 commit comments