whois 5.0.1 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +26 -0
  3. data/.rubocop_opinionated.yml +157 -0
  4. data/.rubocop_todo.yml +242 -0
  5. data/.simplecov +2 -0
  6. data/.tool-versions +1 -0
  7. data/CHANGELOG.md +68 -53
  8. data/Gemfile +5 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +1 -1
  11. data/Rakefile +12 -17
  12. data/bin/console +1 -0
  13. data/bin/whoisrb +3 -2
  14. data/data/ipv4.json +1 -3
  15. data/data/tld.json +2 -90
  16. data/lib/whois.rb +12 -10
  17. data/lib/whois/client.rb +4 -2
  18. data/lib/whois/errors.rb +4 -2
  19. data/lib/whois/record.rb +3 -1
  20. data/lib/whois/record/part.rb +4 -3
  21. data/lib/whois/server.rb +26 -21
  22. data/lib/whois/server/adapters/afilias.rb +4 -1
  23. data/lib/whois/server/adapters/arin.rb +5 -2
  24. data/lib/whois/server/adapters/arpa.rb +22 -19
  25. data/lib/whois/server/adapters/base.rb +4 -4
  26. data/lib/whois/server/adapters/formatted.rb +4 -2
  27. data/lib/whois/server/adapters/none.rb +3 -1
  28. data/lib/whois/server/adapters/not_implemented.rb +3 -1
  29. data/lib/whois/server/adapters/standard.rb +4 -2
  30. data/lib/whois/server/adapters/verisign.rb +4 -1
  31. data/lib/whois/server/adapters/web.rb +3 -1
  32. data/lib/whois/server/socket_handler.rb +8 -6
  33. data/lib/whois/version.rb +4 -2
  34. data/spec/integration/whois_spec.rb +6 -6
  35. data/spec/spec_helper.rb +4 -2
  36. data/spec/support/helpers/connectivity_helper.rb +2 -0
  37. data/spec/support/helpers/spec_helper.rb +2 -0
  38. data/spec/whois/client_spec.rb +6 -7
  39. data/spec/whois/record/part_spec.rb +4 -4
  40. data/spec/whois/record_spec.rb +9 -7
  41. data/spec/whois/server/adapters/afilias_spec.rb +3 -3
  42. data/spec/whois/server/adapters/arin_spec.rb +7 -8
  43. data/spec/whois/server/adapters/arpa_spec.rb +2 -2
  44. data/spec/whois/server/adapters/base_spec.rb +13 -13
  45. data/spec/whois/server/adapters/formatted_spec.rb +7 -7
  46. data/spec/whois/server/adapters/none_spec.rb +2 -2
  47. data/spec/whois/server/adapters/not_implemented_spec.rb +3 -3
  48. data/spec/whois/server/adapters/standard_spec.rb +5 -5
  49. data/spec/whois/server/adapters/verisign_spec.rb +3 -3
  50. data/spec/whois/server/adapters/web_spec.rb +3 -3
  51. data/spec/whois/server/socket_handler_spec.rb +7 -5
  52. data/spec/whois/server_spec.rb +31 -29
  53. data/spec/whois/{errors_spec.rb → web_interface_error_spec.rb} +4 -4
  54. data/spec/whois/whois_spec.rb +3 -3
  55. metadata +11 -8
  56. data/tasks/spec.rake +0 -199
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "whois"
data/bin/whoisrb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift(File.expand_path("../../lib", __FILE__))
4
+ $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
4
5
 
5
6
  require 'optparse'
6
7
  require 'whois'
@@ -8,7 +9,7 @@ require 'whois'
8
9
 
9
10
  options = {}
10
11
  OptionParser.new do |opts|
11
- opts.banner = "Whois: an intelligent pure Ruby WHOIS client"
12
+ opts.banner = "Whois: an intelligent pure Ruby WHOIS client"
12
13
  opts.define_head "Usage: whoisrb [options] object"
13
14
  opts.separator ""
14
15
  opts.separator "Examples:"
data/data/ipv4.json CHANGED
@@ -39,9 +39,7 @@
39
39
  "host": "whois.apnic.net"
40
40
  },
41
41
  "43.0.0.0/8": {
42
- "host": "whois.nic.ad.jp",
43
- "adapter": "formatted",
44
- "format": "%s/e"
42
+ "host": "whois.apnic.net"
45
43
  },
46
44
  "46.0.0.0/8": {
47
45
  "host": "whois.ripe.net"
data/data/tld.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "_": {
3
3
  "schema": "2",
4
- "updated": "2019-09-19 11:00:00 UTC"
4
+ "updated": "2021-03-02 11:02:00 UTC"
5
5
  },
6
6
  "aaa": {
7
7
  "_type": "newgtld",
@@ -654,11 +654,6 @@
654
654
  "bn": {
655
655
  "host": "whois.bnnic.bn"
656
656
  },
657
- "bnl": {
658
- "_group": "afiliassrs",
659
- "_type": "newgtld",
660
- "host": "whois.nic.bnl"
661
- },
662
657
  "bnpparibas": {
663
658
  "_group": "afiliassrs",
664
659
  "_type": "newgtld",
@@ -927,10 +922,6 @@
927
922
  "_type": "newgtld",
928
923
  "host": "whois.uniregistry.net"
929
924
  },
930
- "cartier": {
931
- "_type": "newgtld",
932
- "adapter": "none"
933
- },
934
925
  "casa": {
935
926
  "_group": "mmregistry",
936
927
  "_type": "newgtld",
@@ -1071,11 +1062,6 @@
1071
1062
  "_type": "newgtld",
1072
1063
  "host": "whois.nic.google"
1073
1064
  },
1074
- "chrysler": {
1075
- "_group": "afiliassrs",
1076
- "_type": "newgtld",
1077
- "host": "whois.afilias-srs.net"
1078
- },
1079
1065
  "church": {
1080
1066
  "_group": "donuts",
1081
1067
  "_type": "newgtld",
@@ -1694,11 +1680,6 @@
1694
1680
  "_type": "newgtld",
1695
1681
  "host": "whois.nic.doctor"
1696
1682
  },
1697
- "dodge": {
1698
- "_group": "afiliassrs",
1699
- "_type": "newgtld",
1700
- "host": "whois.afilias-srs.net"
1701
- },
1702
1683
  "dog": {
1703
1684
  "_group": "donuts",
1704
1685
  "_type": "newgtld",
@@ -1744,10 +1725,6 @@
1744
1725
  "_type": "newgtld",
1745
1726
  "host": "whois.nic.dunlop"
1746
1727
  },
1747
- "duns": {
1748
- "_type": "newgtld",
1749
- "adapter": "none"
1750
- },
1751
1728
  "dupont": {
1752
1729
  "_type": "newgtld",
1753
1730
  "adapter": "none"
@@ -1900,10 +1877,6 @@
1900
1877
  "_type": "newgtld",
1901
1878
  "host": "whois.nic.events"
1902
1879
  },
1903
- "everbank": {
1904
- "_type": "newgtld",
1905
- "host": "whois.nic.everbank"
1906
- },
1907
1880
  "exchange": {
1908
1881
  "_group": "donuts",
1909
1882
  "_type": "newgtld",
@@ -2953,10 +2926,6 @@
2953
2926
  "is": {
2954
2927
  "host": "whois.isnic.is"
2955
2928
  },
2956
- "iselect": {
2957
- "_type": "newgtld",
2958
- "host": "whois.nic.iselect"
2959
- },
2960
2929
  "ismaili": {
2961
2930
  "_group": "afiliassrs",
2962
2931
  "_type": "newgtld",
@@ -3226,10 +3195,6 @@
3226
3195
  "_type": "newgtld",
3227
3196
  "host": "whois.nic.lacaixa"
3228
3197
  },
3229
- "ladbrokes": {
3230
- "_type": "newgtld",
3231
- "host": "whois.nic.ladbrokes"
3232
- },
3233
3198
  "lamborghini": {
3234
3199
  "_group": "afiliassrs",
3235
3200
  "_type": "newgtld",
@@ -3250,10 +3215,6 @@
3250
3215
  "_type": "newgtld",
3251
3216
  "host": "whois.afilias-srs.net"
3252
3217
  },
3253
- "lancome": {
3254
- "_type": "newgtld",
3255
- "host": "whois.nic.lancome"
3256
- },
3257
3218
  "land": {
3258
3219
  "_group": "donuts",
3259
3220
  "_type": "newgtld",
@@ -3343,10 +3304,6 @@
3343
3304
  "li": {
3344
3305
  "host": "whois.nic.li"
3345
3306
  },
3346
- "liaison": {
3347
- "_type": "newgtld",
3348
- "host": "whois.nic.liaison"
3349
- },
3350
3307
  "lidl": {
3351
3308
  "_type": "newgtld",
3352
3309
  "host": "whois.nic.lidl"
@@ -3742,10 +3699,6 @@
3742
3699
  "_type": "newgtld",
3743
3700
  "host": "whois.nic.mobile"
3744
3701
  },
3745
- "mobily": {
3746
- "_type": "newgtld",
3747
- "adapter": "none"
3748
- },
3749
3702
  "moda": {
3750
3703
  "_group": "donuts",
3751
3704
  "_type": "newgtld",
@@ -3783,11 +3736,6 @@
3783
3736
  "_type": "newgtld",
3784
3737
  "adapter": "none"
3785
3738
  },
3786
- "mopar": {
3787
- "_group": "afiliassrs",
3788
- "_type": "newgtld",
3789
- "host": "whois.afilias-srs.net"
3790
- },
3791
3739
  "mormon": {
3792
3740
  "_group": "afiliassrs",
3793
3741
  "_type": "newgtld",
@@ -3821,11 +3769,6 @@
3821
3769
  "_type": "newgtld",
3822
3770
  "host": "whois.nic.movie"
3823
3771
  },
3824
- "movistar": {
3825
- "_group": "knipp",
3826
- "_type": "newgtld",
3827
- "host": "whois-fe.movistar.tango.knipp.de"
3828
- },
3829
3772
  "mp": {
3830
3773
  "adapter": "none"
3831
3774
  },
@@ -4383,10 +4326,6 @@
4383
4326
  "_type": "newgtld",
4384
4327
  "host": "whois.nic.physio"
4385
4328
  },
4386
- "piaget": {
4387
- "_type": "newgtld",
4388
- "adapter": "none"
4389
- },
4390
4329
  "pics": {
4391
4330
  "_group": "uniregistry",
4392
4331
  "_type": "newgtld",
@@ -5280,11 +5219,6 @@
5280
5219
  "_type": "newgtld",
5281
5220
  "host": "whois.afilias-srs.net"
5282
5221
  },
5283
- "srt": {
5284
- "_group": "afiliassrs",
5285
- "_type": "newgtld",
5286
- "host": "whois.afilias-srs.net"
5287
- },
5288
5222
  "ss": {
5289
5223
  "host": "whois.nic.ss"
5290
5224
  },
@@ -5305,10 +5239,6 @@
5305
5239
  "_type": "newgtld",
5306
5240
  "host": "whois.nic.star"
5307
5241
  },
5308
- "starhub": {
5309
- "_type": "newgtld",
5310
- "host": "whois.nic.starhub"
5311
- },
5312
5242
  "statebank": {
5313
5243
  "_group": "afiliassrs",
5314
5244
  "_type": "newgtld",
@@ -5344,7 +5274,7 @@
5344
5274
  },
5345
5275
  "stream": {
5346
5276
  "_type": "newgtld",
5347
- "adapter": "none"
5277
+ "host": "whois.nic.stream"
5348
5278
  },
5349
5279
  "studio": {
5350
5280
  "_group": "donuts",
@@ -5512,11 +5442,6 @@
5512
5442
  "tel": {
5513
5443
  "host": "whois.nic.tel"
5514
5444
  },
5515
- "telefonica": {
5516
- "_group": "knipp",
5517
- "_type": "newgtld",
5518
- "host": "whois-fe.telefonica.tango.knipp.de"
5519
- },
5520
5445
  "temasek": {
5521
5446
  "_group": "afiliassrs",
5522
5447
  "_type": "newgtld",
@@ -5770,11 +5695,6 @@
5770
5695
  "_type": "newgtld",
5771
5696
  "host": "whois.nic.ubs"
5772
5697
  },
5773
- "uconnect": {
5774
- "_group": "afiliassrs",
5775
- "_type": "newgtld",
5776
- "host": "whois.afilias-srs.net"
5777
- },
5778
5698
  "ug": {
5779
5699
  "host": "whois.co.ug"
5780
5700
  },
@@ -6034,10 +5954,6 @@
6034
5954
  "_type": "newgtld",
6035
5955
  "host": "whois.nic.wanggou"
6036
5956
  },
6037
- "warman": {
6038
- "_type": "newgtld",
6039
- "host": "whois.nic.warman"
6040
- },
6041
5957
  "watch": {
6042
5958
  "_group": "donuts",
6043
5959
  "_type": "newgtld",
@@ -6577,10 +6493,6 @@
6577
6493
  "adapter": "web",
6578
6494
  "url": "http://idn.jo/whois_a.aspx"
6579
6495
  },
6580
- "xn--mgbb9fbpob": {
6581
- "_type": "newgtld",
6582
- "adapter": "none"
6583
- },
6584
6496
  "xn--mgbbh1a": {
6585
6497
  "_type": "newgtld",
6586
6498
  "host": "whois.registry.in"
data/lib/whois.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Ruby Whois
3
5
  #
4
6
  # An intelligent pure Ruby WHOIS client and parser.
5
7
  #
6
- # Copyright (c) 2009-2020 Simone Carletti <weppos@weppos.net>
8
+ # Copyright (c) 2009-2021 Simone Carletti <weppos@weppos.net>
7
9
  #++
8
10
 
9
11
 
@@ -45,11 +47,11 @@ module Whois
45
47
  return
46
48
  end
47
49
 
48
- deprecate(%Q{Whois.available? is deprecated. Call Whois.whois("#{object}").available?})
50
+ deprecate(%{Whois.available? is deprecated. Call Whois.whois("#{object}").available?})
49
51
 
50
52
  result = lookup(object).parser.available?
51
53
  if result.nil?
52
- warn "This method is not supported for this kind of object.\n" +
54
+ warn "This method is not supported for this kind of object.\n" \
53
55
  "Use Whois.lookup('#{object}') instead."
54
56
  end
55
57
  result
@@ -62,11 +64,11 @@ module Whois
62
64
  return
63
65
  end
64
66
 
65
- deprecate(%Q{Whois.registered? is deprecated. Call Whois.whois("#{object}").available?})
67
+ deprecate(%{Whois.registered? is deprecated. Call Whois.whois("#{object}").available?})
66
68
 
67
69
  result = lookup(object).parser.registered?
68
70
  if result.nil?
69
- warn "This method is not supported for this kind of object.\n" +
71
+ warn "This method is not supported for this kind of object.\n" \
70
72
  "Use Whois.lookup('#{object}') instead."
71
73
  end
72
74
  result
@@ -87,9 +89,9 @@ module Whois
87
89
  # @api private
88
90
  # @private
89
91
  def bug!(error, message)
90
- raise error, message.dup <<
91
- " Please report the issue at" <<
92
- " http://github.com/weppos/whois/issues"
92
+ raise error, message.dup <<
93
+ " Please report the issue at" \
94
+ " http://github.com/weppos/whois/issues"
93
95
  end
94
96
 
95
97
 
@@ -107,10 +109,10 @@ module Whois
107
109
  end
108
110
 
109
111
  def extract_callstack(callstack)
110
- gem_root = File.expand_path("../../../", __FILE__) + "/"
112
+ gem_root = "#{File.expand_path('../..', __dir__)}/"
111
113
  offending_line = callstack.find { |line| !line.start_with?(gem_root) } || callstack.first
112
114
  if offending_line
113
- if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
115
+ if (md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/))
114
116
  md.captures
115
117
  else
116
118
  offending_line
data/lib/whois/client.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Ruby Whois
3
5
  #
4
6
  # An intelligent pure Ruby WHOIS client and parser.
5
7
  #
6
- # Copyright (c) 2009-2020 Simone Carletti <weppos@weppos.net>
8
+ # Copyright (c) 2009-2021 Simone Carletti <weppos@weppos.net>
7
9
  #++
8
10
 
9
11
 
@@ -88,7 +90,7 @@ module Whois
88
90
  #
89
91
  def lookup(object)
90
92
  string = object.to_s.downcase
91
- Timeout::timeout(timeout) do
93
+ Timeout.timeout(timeout) do
92
94
  @server = Server.guess(string)
93
95
  @server.configure(settings)
94
96
  @server.lookup(string)
data/lib/whois/errors.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Ruby Whois
3
5
  #
4
6
  # An intelligent pure Ruby WHOIS client and parser.
5
7
  #
6
- # Copyright (c) 2009-2020 Simone Carletti <weppos@weppos.net>
8
+ # Copyright (c) 2009-2021 Simone Carletti <weppos@weppos.net>
7
9
  #++
8
10
 
9
11
 
@@ -69,7 +71,7 @@ module Whois
69
71
 
70
72
  # Raised when the class has found a server but it doesn't support the
71
73
  # standard WHOIS interface via port 43. This is the case of some
72
- # specific domains that only provide a webbased WHOIS interface. (\x01)
74
+ # specific domains that only provide a web-based WHOIS interface. (\x01)
73
75
  class WebInterfaceError < InterfaceNotSupported
74
76
 
75
77
  # @return [String] The URL of the web-based WHOIS interface.
data/lib/whois/record.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Ruby Whois
3
5
  #
4
6
  # An intelligent pure Ruby WHOIS client and parser.
5
7
  #
6
- # Copyright (c) 2009-2020 Simone Carletti <weppos@weppos.net>
8
+ # Copyright (c) 2009-2021 Simone Carletti <weppos@weppos.net>
7
9
  #++
8
10
 
9
11
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Ruby Whois
3
5
  #
4
6
  # An intelligent pure Ruby WHOIS client and parser.
5
7
  #
6
- # Copyright (c) 2009-2020 Simone Carletti <weppos@weppos.net>
8
+ # Copyright (c) 2009-2021 Simone Carletti <weppos@weppos.net>
7
9
  #++
8
10
 
9
11
 
@@ -20,8 +22,7 @@ module Whois
20
22
  # @attr [String] body The body containing the WHOIS output.
21
23
  # @attr [String] host The host which returned the body.
22
24
  #
23
- class Part < Struct.new(:body, :host)
24
-
25
+ Part = Struct.new(:body, :host) do
25
26
  def initialize(*args)
26
27
  if args.first.is_a? Hash
27
28
  initialize_with_hash(args.first)
data/lib/whois/server.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  #--
3
4
  # Ruby Whois
4
5
  #
5
6
  # An intelligent pure Ruby WHOIS client and parser.
6
7
  #
7
- # Copyright (c) 2009-2020 Simone Carletti <weppos@weppos.net>
8
+ # Copyright (c) 2009-2021 Simone Carletti <weppos@weppos.net>
8
9
  #++
9
10
 
10
11
 
@@ -40,11 +41,11 @@ module Whois
40
41
 
41
42
  # @return [Array<Symbol>] the definition types
42
43
  TYPES = [
43
- TYPE_TLD = :tld,
44
- TYPE_IPV4 = :ipv4,
45
- TYPE_IPV6 = :ipv6,
46
- TYPE_ASN16 = :asn16,
47
- TYPE_ASN32 = :asn32,
44
+ TYPE_TLD = :tld,
45
+ TYPE_IPV4 = :ipv4,
46
+ TYPE_IPV6 = :ipv6,
47
+ TYPE_ASN16 = :asn16,
48
+ TYPE_ASN32 = :asn32,
48
49
  ].freeze
49
50
 
50
51
  # Empty hash constant used to save allocation for definitions with empty settings.
@@ -67,7 +68,7 @@ module Whois
67
68
  # @return [void]
68
69
  def load_definitions
69
70
  clear_definitions
70
- Dir[File.expand_path("../../../data/*.json", __FILE__)].each { |f| load_json(f) }
71
+ Dir[File.expand_path('../../data/*.json', __dir__)].each { |f| load_json(f) }
71
72
  end
72
73
 
73
74
  # Loads the definitions from a JSON file.
@@ -77,16 +78,17 @@ module Whois
77
78
  # @return [void]
78
79
  def load_json(file)
79
80
  type = File.basename(file, File.extname(file)).to_sym
80
- JSON.load(File.read(file)).each do |allocation, settings|
81
+ JSON.parse(File.read(file)).each do |allocation, settings|
81
82
  next if allocation == "_"
83
+
82
84
  settings.reject! { |k, _| k.start_with?("_") }
83
85
  host = settings.delete("host")
84
86
  host = intern_string(host) if host
85
87
  options = if settings.empty?
86
- EMPTY_HASH
87
- else
88
- Hash[settings.map { |k,v| [k.to_sym, v.is_a?(String) ? intern_string(v) : v] }].freeze
89
- end
88
+ EMPTY_HASH
89
+ else
90
+ settings.map { |k, v| [k.to_sym, v.is_a?(String) ? intern_string(v) : v] }.to_h.freeze
91
+ end
90
92
  define(type, allocation, host, options)
91
93
  end
92
94
  end
@@ -112,7 +114,7 @@ module Whois
112
114
  #
113
115
  def definitions(type)
114
116
  TYPES.include?(type) or
115
- raise(ArgumentError, "`#{type}` is not a valid definition type")
117
+ raise(ArgumentError, "`#{type}` is not a valid definition type")
116
118
 
117
119
  _definitions(type).values
118
120
  end
@@ -156,7 +158,7 @@ module Whois
156
158
  #
157
159
  def define(type, allocation, host, options = EMPTY_HASH)
158
160
  TYPES.include?(type) or
159
- raise(ArgumentError, "`#{type}` is not a valid definition type")
161
+ raise(ArgumentError, "`#{type}` is not a valid definition type")
160
162
 
161
163
  _definitions(type)[allocation] = [allocation, host, options.freeze]
162
164
  end
@@ -282,6 +284,7 @@ module Whois
282
284
  end
283
285
  rescue ArgumentError
284
286
  # continue
287
+ nil
285
288
  end
286
289
  raise AllocationUnknown, "IP Allocation for `#{string}' unknown"
287
290
  end
@@ -304,7 +307,7 @@ module Whois
304
307
  token = string
305
308
  defs = _definitions(TYPE_TLD)
306
309
 
307
- while token != "" do
310
+ while token != ""
308
311
  if (found = defs[token])
309
312
  return factory(:tld, *found)
310
313
  else
@@ -328,7 +331,7 @@ module Whois
328
331
  # that matches one of the existing server definitions.
329
332
  def find_for_asn(string)
330
333
  asn = string[/\d+/].to_i
331
- asn_type = asn <= 65535 ? TYPE_ASN16 : TYPE_ASN32
334
+ asn_type = asn <= 65_535 ? TYPE_ASN16 : TYPE_ASN32
332
335
  _definitions(asn_type).each do |_, definition|
333
336
  if (range = definition.first.split.map(&:to_i)) && asn >= range.first && asn <= range.last
334
337
  return factory(asn_type, *definition)
@@ -379,9 +382,10 @@ module Whois
379
382
  end
380
383
 
381
384
  def valid_ipv4?(addr)
382
- if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ addr
383
- return $~.captures.all? {|i| i.to_i < 256}
385
+ if (m = /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/.match(addr))
386
+ return m.captures.all? { |i| i.to_i < 256 }
384
387
  end
388
+
385
389
  false
386
390
  end
387
391
 
@@ -391,9 +395,10 @@ module Whois
391
395
  return true if addr.match?(/\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/)
392
396
  return true if addr.match?(/\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/)
393
397
  # IPv6 (IPv4 compat)
394
- return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?($')
395
- return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?($')
396
- return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?($')
398
+ return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
399
+ return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
400
+ return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?(Regexp.last_match.post_match)
401
+
397
402
  false
398
403
  end
399
404