domain_name 0.5.11 → 0.5.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0eafc47a4b3dfe9f636fec6cb6705d0dec0bd44a
4
- data.tar.gz: 5ffe41e86eddfcd6507808b68f61d360af8eee9f
3
+ metadata.gz: dd0379bf0cffbaf14dcf3006b9730ebd1b1c1332
4
+ data.tar.gz: 1bc901f30c3e6b574b05c34bcd1ba9a082052fc3
5
5
  SHA512:
6
- metadata.gz: 770918024fa90f8ea009cb899bc98386140cf2deea2be85a7172217b0e7b627647a4ca737699bdbf8ffe6a99c50c2d0ac00cad6e078094d72b13cc129e4687f0
7
- data.tar.gz: f8b2089004b251798c407995e5a5539bb7f2b71a5624b22c4c77decf045eb77e71ec42ac31e8e9a5619e29c15c4ad24e42781c2fe8d43cb18a1197828bd49ece
6
+ metadata.gz: 62d3caed3da3692ea0d37db18f8079aebfd6a64fdc31b22acd1824eb6a43d51850a8b81a1bfc59597fecf6a5f9d3246440fbe5e2a85b2ec7aa67f9ed9eb24d2d
7
+ data.tar.gz: 13573bc251f0356604e1409e4da30365ddfa3b31e0d2c0968b87ec171ffedef0e62a9726ba63c736093e9195cec6f15103fa4fed3c8490787f6036fa03ee43b0
data/README.md CHANGED
@@ -24,12 +24,14 @@ Description
24
24
  host.ipaddr? #=> true
25
25
  host.cookie_domain?("0:0:0:0:0:0:0:1") #=> true
26
26
 
27
+ * Implements rudimental IDNA support.
27
28
 
28
29
  To-do's
29
30
  -------
30
31
 
31
- * Implement the strict domain label validation defined in RFC 5891 and
32
- 5892. It will be worked on on the `unicode` branch.
32
+ * Implement IDNA 2008 (and/or 2003) including the domain label
33
+ validation and mapping defined in RFC 5891-5895 and UTS #46.
34
+ (work in progress)
33
35
 
34
36
  * Define a compact YAML serialization format.
35
37
 
data/Rakefile CHANGED
@@ -9,26 +9,25 @@ task :default => :test
9
9
 
10
10
  task :test => ETLD_DATA_RB
11
11
 
12
- file ETLD_DATA_RB => [
13
- ETLD_DATA_FILE,
14
- ETLD_DATA_RB + '.erb',
15
- 'tool/gen_etld_data.rb'
16
- ] do
17
- ruby 'tool/gen_etld_data.rb'
18
- end
19
-
20
12
  task :import => :etld_data
21
13
 
14
+ #
15
+ # eTLD Database
16
+ #
17
+
22
18
  task :etld_data do
23
19
  require 'open-uri'
24
20
  require 'time'
25
21
 
26
22
  begin
27
- load File.join('.', ETLD_DATA_RB)
28
-
29
- data = ETLD_DATA_URI.read(
30
- 'If-Modified-Since' => Time.parse(DomainName::ETLD_DATA_DATE).rfc2822
31
- )
23
+ begin
24
+ load File.join('.', ETLD_DATA_RB)
25
+ data = ETLD_DATA_URI.read(
26
+ 'If-Modified-Since' => Time.parse(DomainName::ETLD_DATA_DATE).rfc2822
27
+ )
28
+ rescue LoadError, NameError
29
+ data = ETLD_DATA_URI.read
30
+ end
32
31
  puts 'eTLD database is modified.'
33
32
  File.write(ETLD_DATA_FILE, data)
34
33
  File.utime Time.now, data.last_modified, ETLD_DATA_FILE
@@ -42,6 +41,14 @@ task :etld_data do
42
41
  end
43
42
  end
44
43
 
44
+ file ETLD_DATA_RB => [
45
+ ETLD_DATA_FILE,
46
+ ETLD_DATA_RB + '.erb',
47
+ 'tool/gen_etld_data.rb'
48
+ ] do
49
+ ruby 'tool/gen_etld_data.rb'
50
+ end
51
+
45
52
  require 'rake/testtask'
46
53
  Rake::TestTask.new(:test) do |test|
47
54
  test.libs << 'test'
@@ -6561,6 +6561,26 @@ xxx
6561
6561
  // Requested by Donavan Miller <donavanm@amazon.com> 2013-03-22
6562
6562
  cloudfront.net
6563
6563
 
6564
+ // Amazon Elastic Compute Cloud: https://aws.amazon.com/ec2/
6565
+ // Requested by Osman Surkatty <osmans@amazon.com> 2013-04-02
6566
+ compute.amazonaws.com
6567
+ us-east-1.amazonaws.com
6568
+ compute-1.amazonaws.com
6569
+ z-1.compute-1.amazonaws.com
6570
+ z-2.compute-1.amazonaws.com
6571
+ ap-northeast-1.compute.amazonaws.com
6572
+ ap-southeast-1.compute.amazonaws.com
6573
+ ap-southeast-2.compute.amazonaws.com
6574
+ eu-west-1.compute.amazonaws.com
6575
+ sa-east-1.compute.amazonaws.com
6576
+ us-gov-west-1.compute.amazonaws.com
6577
+ us-west-1.compute.amazonaws.com
6578
+ us-west-2.compute.amazonaws.com
6579
+
6580
+ // Amazon Elastic Beanstalk : https://aws.amazon.com/elasticbeanstalk/
6581
+ // Requested by Adam Stein <astein@amazon.com> 2013-04-02
6582
+ elasticbeanstalk.com
6583
+
6564
6584
  // Amazon Elastic Load Balancing : https://aws.amazon.com/elasticloadbalancing/
6565
6585
  // Requested by Scott Vidmar <svidmar@amazon.com> 2013-03-27
6566
6586
  elb.amazonaws.com
@@ -6916,6 +6936,10 @@ webhop.org
6916
6936
  worse-than.tv
6917
6937
  writesthisblog.com
6918
6938
 
6939
+ // GitHub, Inc.
6940
+ // Requested by Ben Toews <btoews@github.com> 2013-04-18
6941
+ github.io
6942
+
6919
6943
  // Google, Inc.
6920
6944
  // Requested by Eduardo Vela <evn@google.com> 2012-10-24
6921
6945
  appspot.com
@@ -6963,6 +6987,11 @@ codespot.com
6963
6987
  googleapis.com
6964
6988
  googlecode.com
6965
6989
 
6990
+ // Heroku : https://www.heroku.com/
6991
+ // Requested by Tom Maher <tmaher@heroku.com> 2013-05-02
6992
+ herokuapp.com
6993
+ herokussl.com
6994
+
6966
6995
  // iki.fi
6967
6996
  // Requested by Hannu Aronsson <haa@iki.fi> 2009-11-05
6968
6997
  iki.fi
data/lib/domain_name.rb CHANGED
@@ -20,6 +20,10 @@ class DomainName
20
20
  # suitable for opening a connection to.
21
21
  attr_reader :hostname
22
22
 
23
+ # The Unicode representation of the #hostname property.
24
+ #
25
+ # :attr_reader: hostname_idn
26
+
23
27
  # The least "universally original" domain part of this domain name.
24
28
  # For example, "example.co.uk" for "www.sub.example.co.uk". This
25
29
  # may be nil if the hostname does not have one, like when it is an
@@ -27,6 +31,10 @@ class DomainName
27
31
  # non-canonical domain.
28
32
  attr_reader :domain
29
33
 
34
+ # The Unicode representation of the #domain property.
35
+ #
36
+ # :attr_reader: domain_idn
37
+
30
38
  # The TLD part of this domain name. For example, if the hostname is
31
39
  # "www.sub.example.co.uk", the TLD part is "uk". This property is
32
40
  # nil only if +ipaddr?+ is true. This may be nil if the hostname
@@ -34,6 +42,10 @@ class DomainName
34
42
  # non-canonical domain.
35
43
  attr_reader :tld
36
44
 
45
+ # The Unicode representation of the #tld property.
46
+ #
47
+ # :attr_reader: tld_idn
48
+
37
49
  # Returns an IPAddr object if this is an IP address.
38
50
  attr_reader :ipaddr
39
51
 
@@ -230,6 +242,35 @@ class DomainName
230
242
 
231
243
  alias to_str to_s
232
244
 
245
+ def hostname_idn
246
+ @hostname_idn ||=
247
+ if @ipaddr
248
+ @hostname
249
+ else
250
+ DomainName::Punycode.decode_hostname(@hostname)
251
+ end
252
+ end
253
+
254
+ alias idn hostname_idn
255
+
256
+ def domain_idn
257
+ @domain_idn ||=
258
+ if @ipaddr
259
+ @domain
260
+ else
261
+ DomainName::Punycode.decode_hostname(@domain)
262
+ end
263
+ end
264
+
265
+ def tld_idn
266
+ @tld_idn ||=
267
+ if @ipaddr
268
+ @tld
269
+ else
270
+ DomainName::Punycode.decode_hostname(@tld)
271
+ end
272
+ end
273
+
233
274
  def inspect
234
275
  str = '#<%s:%s' % [self.class.name, @hostname]
235
276
  if @ipaddr
@@ -1,5 +1,5 @@
1
1
  class DomainName
2
- ETLD_DATA_DATE = '2013-04-05T23:00:49Z'
2
+ ETLD_DATA_DATE = '2013-06-06T23:00:56Z'
3
3
 
4
4
  ETLD_DATA = {
5
5
  "ac" => 0,
@@ -5717,6 +5717,20 @@ class DomainName
5717
5717
  "zm" => -1,
5718
5718
  "zw" => -1,
5719
5719
  "cloudfront.net" => 0,
5720
+ "compute.amazonaws.com" => 0,
5721
+ "us-east-1.amazonaws.com" => 0,
5722
+ "compute-1.amazonaws.com" => 0,
5723
+ "z-1.compute-1.amazonaws.com" => 0,
5724
+ "z-2.compute-1.amazonaws.com" => 0,
5725
+ "ap-northeast-1.compute.amazonaws.com" => 0,
5726
+ "ap-southeast-1.compute.amazonaws.com" => 0,
5727
+ "ap-southeast-2.compute.amazonaws.com" => 0,
5728
+ "eu-west-1.compute.amazonaws.com" => 0,
5729
+ "sa-east-1.compute.amazonaws.com" => 0,
5730
+ "us-gov-west-1.compute.amazonaws.com" => 0,
5731
+ "us-west-1.compute.amazonaws.com" => 0,
5732
+ "us-west-2.compute.amazonaws.com" => 0,
5733
+ "elasticbeanstalk.com" => 0,
5720
5734
  "elb.amazonaws.com" => 0,
5721
5735
  "s3.amazonaws.com" => 0,
5722
5736
  "s3-us-west-2.amazonaws.com" => 0,
@@ -6049,6 +6063,7 @@ class DomainName
6049
6063
  "webhop.org" => 0,
6050
6064
  "worse-than.tv" => 0,
6051
6065
  "writesthisblog.com" => 0,
6066
+ "github.io" => 0,
6052
6067
  "appspot.com" => 0,
6053
6068
  "blogspot.be" => 0,
6054
6069
  "blogspot.bj" => 0,
@@ -6093,6 +6108,8 @@ class DomainName
6093
6108
  "codespot.com" => 0,
6094
6109
  "googleapis.com" => 0,
6095
6110
  "googlecode.com" => 0,
6111
+ "herokuapp.com" => 0,
6112
+ "herokussl.com" => 0,
6096
6113
  "iki.fi" => 0,
6097
6114
  "biz.at" => 0,
6098
6115
  "info.at" => 0,
@@ -2,7 +2,7 @@
2
2
  #--
3
3
  # punycode.rb - PunyCode encoder for the Domain Name library
4
4
  #
5
- # Copyright (C) 2011, 2012 Akinori MUSHA, All rights reserved.
5
+ # Copyright (C) 2011, 2012, 2013 Akinori MUSHA, All rights reserved.
6
6
  #
7
7
  # Ported from puny.c, a part of VeriSign XCode (encode/decode) IDN
8
8
  # Library.
@@ -57,7 +57,7 @@ class DomainName
57
57
  DAMP = 700
58
58
  INITIAL_BIAS = 72
59
59
  INITIAL_N = 0x80
60
- DELIMITER = '-'
60
+ DELIMITER = '-'.freeze
61
61
 
62
62
  MAXINT = (1 << 32) - 1
63
63
 
@@ -66,6 +66,9 @@ class DomainName
66
66
 
67
67
  RE_NONBASIC = /[^\x00-\x7f]/
68
68
 
69
+ # Returns the numeric value of a basic code point (for use in
70
+ # representing integers) in the range 0 to base-1, or nil if cp
71
+ # is does not represent a value.
69
72
  DECODE_DIGIT = {}.tap { |map|
70
73
  # ASCII A..Z map to 0..25
71
74
  # ASCII a..z map to 0..25
@@ -74,34 +77,26 @@ class DomainName
74
77
  (26..35).each { |i| map[22 + i] = i }
75
78
  }
76
79
 
80
+ # Returns the basic code point whose value (when used for
81
+ # representing integers) is d, which must be in the range 0 to
82
+ # BASE-1. The lowercase form is used unless flag is true, in
83
+ # which case the uppercase form is used. The behavior is
84
+ # undefined if flag is nonzero and digit d has no uppercase
85
+ # form.
86
+ ENCODE_DIGIT = proc { |d, flag|
87
+ (d + 22 + (d < 26 ? 75 : 0) - (flag ? (1 << 5) : 0)).chr
88
+ # 0..25 map to ASCII a..z or A..Z
89
+ # 26..35 map to ASCII 0..9
90
+ }
91
+
92
+ DOT = '.'.freeze
93
+ PREFIX = 'xn--'.freeze
94
+
77
95
  # Most errors we raise are basically kind of ArgumentError.
78
96
  class ArgumentError < ::ArgumentError; end
79
97
  class BufferOverflowError < ArgumentError; end
80
98
 
81
99
  class << self
82
- private
83
-
84
- # Returns the basic code point whose value (when used for
85
- # representing integers) is d, which must be in the range 0 to
86
- # BASE-1. The lowercase form is used unless flag is true, in
87
- # which case the uppercase form is used. The behavior is
88
- # undefined if flag is nonzero and digit d has no uppercase
89
- # form.
90
- def encode_digit(d, flag)
91
- (d + 22 + (d < 26 ? 75 : 0) - (flag ? (1 << 5) : 0)).chr
92
- # 0..25 map to ASCII a..z or A..Z
93
- # 26..35 map to ASCII 0..9
94
- end
95
-
96
- # Returns the numeric value of a basic code point (for use in
97
- # representing integers) in the range 0 to base-1, or nil if cp
98
- # is does not represent a value.
99
- def decode_digit(cp)
100
- DECODE_DIGIT[cp]
101
- end
102
-
103
- public
104
-
105
100
  # Encode a +string+ in Punycode
106
101
  def encode(string)
107
102
  input = string.unpack('U*')
@@ -154,11 +149,11 @@ class DomainName
154
149
  t = k <= bias ? TMIN : k - bias >= TMAX ? TMAX : k - bias
155
150
  break if q < t
156
151
  q, r = (q - t).divmod(BASE - t)
157
- output << encode_digit(t + r, false)
152
+ output << ENCODE_DIGIT[t + r, false]
158
153
  k += BASE
159
154
  }
160
155
 
161
- output << encode_digit(q, false)
156
+ output << ENCODE_DIGIT[q, false]
162
157
 
163
158
  # Adapt the bias
164
159
  delta = h == b ? delta / DAMP : delta >> 1
@@ -186,13 +181,13 @@ class DomainName
186
181
  def encode_hostname(hostname)
187
182
  hostname.match(RE_NONBASIC) or return hostname
188
183
 
189
- hostname.split('.').map { |name|
184
+ hostname.split(DOT).map { |name|
190
185
  if name.match(RE_NONBASIC)
191
- 'xn--' << encode(name)
186
+ PREFIX + encode(name)
192
187
  else
193
188
  name
194
189
  end
195
- }.join('.')
190
+ }.join(DOT)
196
191
  end
197
192
 
198
193
  # Decode a +string+ encoded in Punycode
@@ -237,7 +232,7 @@ class DomainName
237
232
  k = BASE
238
233
 
239
234
  loop {
240
- digit = decode_digit(input[h]) or
235
+ digit = DECODE_DIGIT[input[h]] or
241
236
  raise ArgumentError, "Illegal character is found in non-basic part: #{string.inspect}"
242
237
  h += 1
243
238
  i += digit * w
@@ -279,7 +274,7 @@ class DomainName
279
274
 
280
275
  # Decode a hostname using IDN/Punycode algorithms
281
276
  def decode_hostname(hostname)
282
- hostname.gsub(/(\A|\.)xn--([^.]*)/) {
277
+ hostname.gsub(/(\A|#{Regexp.quote(DOT)})#{Regexp.quote(PREFIX)}([^#{Regexp.quote(DOT)}]*)/o) {
283
278
  $1 << decode($2)
284
279
  }
285
280
  end
@@ -1,3 +1,3 @@
1
1
  class DomainName
2
- VERSION = "0.5.11"
2
+ VERSION = "0.5.12"
3
3
  end
@@ -1,3 +1,4 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'helper'
2
3
  require 'ipaddr'
3
4
 
@@ -282,4 +283,15 @@ class TestDomainName < Test::Unit::TestCase
282
283
  assert_equal nil, dn.superdomain
283
284
  }
284
285
  end
286
+
287
+ should "have idn methods" do
288
+ dn = DomainName("金八先生.B組.3年.日本語ドメイン名Example.日本")
289
+
290
+ assert_equal "xn--44q1cv48kq8x.xn--b-gf6c.xn--3-pj3b.xn--example-6q4fyliikhk162btq3b2zd4y2o.xn--wgv71a", dn.hostname
291
+ assert_equal "金八先生.b組.3年.日本語ドメイン名example.日本", dn.hostname_idn
292
+ assert_equal "xn--example-6q4fyliikhk162btq3b2zd4y2o.xn--wgv71a", dn.domain
293
+ assert_equal "日本語ドメイン名example.日本", dn.domain_idn
294
+ assert_equal "xn--wgv71a", dn.tld
295
+ assert_equal "日本", dn.tld_idn
296
+ end
285
297
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_name
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akinori MUSHA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-12 00:00:00.000000000 Z
11
+ date: 2013-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unf