diff --git a/ChangeLog b/ChangeLog index 2b70452d3f..f41b3ebeaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Dec 29 05:30:30 2015 Eric Wong + + * lib/resolv.rb (Resolv::IPv6.create): avoid modifying frozen + * test/resolv/test_dns.rb (test_ipv6_create): test for above + [Bug #11910] [ruby-core:72559] + Mon Dec 28 14:55:57 2015 Kuniaki IGARASHI * test/ruby/test_string.rb (TestString#test_rstrip_bang): Add test diff --git a/lib/resolv.rb b/lib/resolv.rb index 61bed16b3f..9a981b99bd 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -2451,14 +2451,14 @@ class Resolv when IPv6 return arg when String - address = '' + address = ''.b if Regex_8Hex =~ arg arg.scan(/[0-9A-Fa-f]+/) {|hex| address << [hex.hex].pack('n')} elsif Regex_CompressedHex =~ arg prefix = $1 suffix = $2 - a1 = '' - a2 = '' + a1 = ''.b + a2 = ''.b prefix.scan(/[0-9A-Fa-f]+/) {|hex| a1 << [hex.hex].pack('n')} suffix.scan(/[0-9A-Fa-f]+/) {|hex| a2 << [hex.hex].pack('n')} omitlen = 16 - a1.length - a2.length @@ -2474,8 +2474,8 @@ class Resolv elsif Regex_CompressedHex4Dec =~ arg prefix, suffix, a, b, c, d = $1, $2, $3.to_i, $4.to_i, $5.to_i, $6.to_i if (0..255) === a && (0..255) === b && (0..255) === c && (0..255) === d - a1 = '' - a2 = '' + a1 = ''.b + a2 = ''.b prefix.scan(/[0-9A-Fa-f]+/) {|hex| a1 << [hex.hex].pack('n')} suffix.scan(/[0-9A-Fa-f]+/) {|hex| a2 << [hex.hex].pack('n')} omitlen = 12 - a1.length - a2.length diff --git a/test/resolv/test_dns.rb b/test/resolv/test_dns.rb index 338130e64f..d1431c1427 100644 --- a/test/resolv/test_dns.rb +++ b/test/resolv/test_dns.rb @@ -199,6 +199,12 @@ class TestResolvDNS < Test::Unit::TestCase assert_equal(expected, labels) end + def test_ipv6_create + ref = '[Bug #11910] [ruby-core:72559]' + assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1') + assert_instance_of Resolv::IPv6, Resolv::IPv6.create('::1:127.0.0.1') + end + def test_too_big_label_address n = 2000 m = Resolv::DNS::Message::MessageEncoder.new {|msg|