diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-28 20:31:10 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-28 20:31:10 +0000 |
commit | a3b53cd9919ff01567ef04af4057b3dec3192471 (patch) | |
tree | 491c726a82fdafabffc33c73a88f2af12b7ee83e | |
parent | d21c54ffbd080645e4f64e01e7859775e22707b7 (diff) | |
download | ruby-a3b53cd9919ff01567ef04af4057b3dec3192471.tar.gz |
Resolv::IPv6.create: avoid modifying frozen string literal
* 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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | lib/resolv.rb | 10 | ||||
-rw-r--r-- | test/resolv/test_dns.rb | 6 |
3 files changed, 17 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Tue Dec 29 05:30:30 2015 Eric Wong <e@80x24.org> + + * 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 <igaiga@gmail.com> * 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| |