File tree 2 files changed +17
-1
lines changed
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -2531,7 +2531,7 @@ def initialize(address) # :nodoc:
2531
2531
attr_reader :address
2532
2532
2533
2533
def to_s # :nodoc:
2534
- address = sprintf ( "%X:%X:%X:%X:%X:%X:%X:%X " , *@address . unpack ( "nnnnnnnn" ) )
2534
+ address = sprintf ( "%x:%x:%x:%x:%x:%x:%x:%x " , *@address . unpack ( "nnnnnnnn" ) )
2535
2535
unless address . sub! ( /(^|:)0(:0)+(:|$)/ , '::' )
2536
2536
address . sub! ( /(^|:)0(:|$)/ , '::' )
2537
2537
end
Original file line number Diff line number Diff line change @@ -216,6 +216,22 @@ def test_ipv6_create
216
216
assert_instance_of Resolv ::IPv6 , Resolv ::IPv6 . create ( '::1:127.0.0.1' ) , ref
217
217
end
218
218
219
+ def test_ipv6_to_s
220
+ test_cases = [
221
+ [ "2001::abcd:abcd:abcd" , "2001::ABcd:abcd:ABCD" ] ,
222
+ [ "2001:db8::1" , "2001:db8::0:1" ] ,
223
+ [ "::" , "0:0:0:0:0:0:0:0" ] ,
224
+ [ "2001::" , "2001::0" ] ,
225
+ [ "2001:db8::1:1:1:1:1" , "2001:db8:0:1:1:1:1:1" ] ,
226
+ [ "1::1:0:0:0:1" , "1:0:0:1:0:0:0:1" ] ,
227
+ [ "1::1:0:0:1" , "1:0:0:0:1:0:0:1" ] ,
228
+ ]
229
+
230
+ test_cases . each do |expected , ipv6 |
231
+ assert_equal expected , Resolv ::IPv6 . create ( ipv6 ) . to_s
232
+ end
233
+ end
234
+
219
235
def test_ipv6_should_be_16
220
236
ref = '[rubygems:1626]'
221
237
You can’t perform that action at this time.
0 commit comments