addressabler 0.0.7 → 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 843009d16f40ee1495e8df0b7cdebc38be93dfc9
4
+ data.tar.gz: e07d20c2fe95ce66837dc8136ef460bb57a15b84
5
+ SHA512:
6
+ metadata.gz: 72479f1ded77aebcd346504fea4071b29047b93bff9b636cdcdca4193eedc6b43caf0452c7d4062243885e05f88d512137756b9293bf93c2bd5d2329b6804b66
7
+ data.tar.gz: 27043e8cdf72fb5f19dbb2a709400faf1d79bf010c5a41640d9eb01207b258c4e4c1f92f06387f2fc39fc34acc6a8863de4a463faff84209ab0f3b783ec231b0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.7
2
+ * Updated to latest TLD list from [publicsuffix.org][]
3
+
1
4
  ## 0.0.6
2
5
  * Merged [pull request from Jean Mertz][] adding custom TLD support
3
6
 
@@ -9,3 +12,4 @@
9
12
  * Updated to latest Addressable spec
10
13
 
11
14
  [pull request from Jean Mertz]: https://github.com/flipsasser/addressabler/pull/2
15
+ [publicsuffix.org]: http://publicsuffix.org/
data/README.md CHANGED
@@ -7,14 +7,11 @@ setting of nested hashes to query strings.
7
7
 
8
8
  ## Install
9
9
 
10
- Install using Rubygems:
10
+ Add Addressabler to your `Gemfile`:
11
11
 
12
- gem install addressabler
13
-
14
- Then:
15
-
16
- require 'rubygems'
17
- require 'addressabler'
12
+ ```ruby
13
+ gem "addressabler", ">= 0.1"
14
+ ```
18
15
 
19
16
  Addressabler will automatically require `addressable/uri`.
20
17
 
@@ -58,12 +55,22 @@ TLDs, as well:
58
55
  @uri.tld #=> "co.uk"
59
56
  ```
60
57
 
58
+ #### Private / Public TLDs
59
+
60
+ By default, Addressabler knows about ICANN public TLDs. There are, however, lots and lots of private TLDs that companies have registered. For example, as Dom Hodgson [points out](https://github.com/flipsasser/addressabler/issues/3), "blogspot.com" is a TLD by private, non-ICANN standards which are applied by the Mozilla foundation to the TLD list.
61
+
62
+ As such, Addressabler defaults to parsing the ICANN public TLDS (`Addressabler.public_tlds`) but can easily be instructed to look at private TLDs like so:
63
+
64
+ ```ruby
65
+ Addressabler.use_private_tlds = true
66
+ ```
67
+
61
68
  #### Custom TLDs
62
69
  You can specify custom TLDs - which aren't actually working TLD's on the
63
70
  internet - for internal usage. One example would be a custom development TLD:
64
71
 
65
72
  ```ruby
66
- Addressable::URI.custom_tlds = {
73
+ Addressabler.custom_tlds = {
67
74
  'dev' => {}, # mydomain.dev
68
75
  'bar' => { 'foo' => {} } # mydomain.foo.bar
69
76
  }
@@ -90,7 +97,7 @@ Frankly, I don't disagree with anything he has to say on the issue, but it is a
90
97
  problem many people have experienced.
91
98
 
92
99
  *As such,* since Rack already supports building nested hashes "the Rails Way"
93
- (shudder), I added support for assigning nested hashes to `URI`s **only if Rack
100
+ (shudder), I added support for assigning nested hashes to `Addressable::URI`s **only if Rack
94
101
  is available.** Addressabler will attempt to load `Rack::Utils` and, if it finds
95
102
  it, you can assign a nested hash in the `query_hash=` method like so:
96
103
 
@@ -99,11 +106,18 @@ it, you can assign a nested hash in the `query_hash=` method like so:
99
106
  @uri.to_s #=> "http://www.google.co.uk/?foo[bar]=baz"
100
107
  ```
101
108
 
102
- **HANDLE WITH CARE!** As [Bob explains in the discussion]
103
- (https://github.com/sporkmonger/addressable/issues/77#issuecomment-8534480),
109
+ **HANDLE WITH CARE!** As [Bob explains in the discussion](https://github.com/sporkmonger/addressable/issues/77#issuecomment-8534480),
104
110
  there's a better alternative to nested hashes in query strings, so try that
105
111
  before you install this library.
106
112
 
107
113
  That's it. Enjoy.
108
114
 
109
- #### Copyright © 2013 Flip Sasser
115
+ ## Contributors THANKS GUYS
116
+
117
+ Super special thankses to
118
+
119
+ * [Jean Mertz](https://github.com/jeanmertz) for the custom [TLD implementation](https://github.com/flipsasser/addressabler/pull/2)
120
+ * [Paul Dix](https://github.com/pauldix) for the [Domainatrix](https://github.com/pauldix/domainatrix) parsing code
121
+ * [Bob Aman](https://github.com/sporkmonger) for maintaining [Addressable](https://github.com/sporkmonger/addressable)
122
+
123
+ #### Copyright © 2013 Flip Sasser
@@ -0,0 +1,62 @@
1
+ require 'addressabler'
2
+ require 'addressabler/query'
3
+ require 'addressable/uri'
4
+
5
+ module Addressabler
6
+ module URI
7
+ def domain
8
+ return nil unless host
9
+ parse_domain_parts[:domain]
10
+ end
11
+
12
+ def domain=(new_domain)
13
+ self.host = "#{subdomain}.#{new_domain}.#{tld}"
14
+ end
15
+
16
+ def query_hash
17
+ @query_hash ||= query_hash_for(query_values || {})
18
+ end
19
+
20
+ def query_hash=(new_query_hash)
21
+ @query_hash = query_hash_for(new_query_hash || {})
22
+ end
23
+
24
+ def subdomain
25
+ return nil unless host
26
+ parse_domain_parts[:subdomain]
27
+ end
28
+
29
+ def subdomain=(new_subdomain)
30
+ self.host = "#{new_subdomain}.#{domain}.#{tld}"
31
+ end
32
+
33
+ def tld
34
+ return nil unless host
35
+ Addressabler.parse_tld(host)
36
+ end
37
+
38
+ def tld=(new_tld)
39
+ self.host = "#{subdomain}.#{domain}.#{new_tld}"
40
+ end
41
+
42
+ private
43
+ def query_hash_for(contents)
44
+ hash = Addressabler::Query[contents]
45
+ hash.uri = self
46
+ hash
47
+ end
48
+
49
+ def parse_domain_parts
50
+ tld = self.tld
51
+ subdomain_parts = host.to_s.gsub(/\.#{tld}$/, '').split('.')
52
+ @domain_parts = {
53
+ :domain => subdomain_parts.pop,
54
+ :subdomain => subdomain_parts.join('.'),
55
+ :tld => tld
56
+ }
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ Addressable::URI.send :include, Addressabler::URI
@@ -0,0 +1,23 @@
1
+ require 'addressabler'
2
+ require 'addressable/uri'
3
+
4
+ module Addressabler
5
+ module URIDeprecation
6
+ def custom_tlds
7
+ deprecate_custom_tlds
8
+ Addressabler.custom_tlds
9
+ end
10
+
11
+ def custom_tlds=(new_custom_tlds)
12
+ deprecate_custom_tlds
13
+ Addressabler.custom_tlds = new_custom_tlds
14
+ end
15
+
16
+ private
17
+ def deprecate_custom_tlds
18
+ Addressabler.deprecation_warning('Addressable::URI.custom_tlds will be replaced with Addressabler.custom_tlds in Addressable 1.0. Please note the deprecated accessor is on "Addressable::URI" and the new accessor is on "Addressable*r*")')
19
+ end
20
+ end
21
+ end
22
+
23
+ Addressable::URI.extend Addressabler::URIDeprecation
data/lib/addressabler.rb CHANGED
@@ -1,88 +1,68 @@
1
1
  require 'rubygems'
2
- require 'addressable/uri'
3
- require 'addressabler/query'
4
-
5
- module Addressable
6
- class URI
7
- class << self; attr_accessor :custom_tlds; end
8
- @custom_tlds = {}
9
- end
10
- end
2
+ require 'addressabler/uri'
3
+ require 'addressabler/uri_deprecation'
11
4
 
12
5
  module Addressabler
13
- module ClassMethods
14
- def parse_tld(host)
15
- host = host.to_s.split('.')
16
- tlds = []
17
- sub_hash = Addressabler::TLDS.merge(@custom_tlds)
18
- while sub_hash = sub_hash[tld = host.pop]
19
- tlds.unshift(tld)
20
- if sub_hash.has_key? '*'
21
- tlds.unshift(host.pop)
22
- end
6
+ def self.all_tlds
7
+ @all_tlds ||= {}.tap do |tlds|
8
+ with_tld_file do |line|
9
+ add_line_to_tlds(line, tlds)
23
10
  end
24
- tlds.join('.')
25
11
  end
26
12
  end
27
13
 
28
- module InstanceMethods
29
- def domain
30
- return nil unless host
31
- parse_domain_parts[:domain]
32
- end
33
-
34
- def domain=(new_domain)
35
- self.host = "#{subdomain}.#{new_domain}.#{tld}"
36
- end
37
-
38
- def query_hash
39
- @query_hash ||= query_hash_for(query_values || {})
40
- end
41
-
42
- def query_hash=(new_query_hash)
43
- @query_hash = query_hash_for(new_query_hash || {})
44
- end
14
+ def self.custom_tlds
15
+ @custom_tlds ||= {}
16
+ end
45
17
 
46
- def subdomain
47
- return nil unless host
48
- parse_domain_parts[:subdomain]
49
- end
18
+ def self.custom_tlds=(new_custom_tlds)
19
+ @custom_tlds = new_custom_tlds
20
+ end
50
21
 
51
- def subdomain=(new_subdomain)
52
- self.host = "#{new_subdomain}.#{domain}.#{tld}"
53
- end
22
+ def self.parse_tld(host)
23
+ host = host.to_s.split('.')
24
+ tlds = []
25
+ tlds = look_for_tld_in(private_tlds, host.dup) if use_private_tlds?
26
+ tlds = look_for_tld_in(public_tlds.merge(custom_tlds), host.dup) if tlds.empty?
27
+ tlds.join('.')
28
+ end
54
29
 
55
- def tld
56
- return nil unless host
57
- self.class.parse_tld(host)
30
+ def self.private_tlds
31
+ @private_tlds ||= {}.tap do |tlds|
32
+ in_private_tlds = false
33
+ with_tld_file do |line|
34
+ if in_private_tlds
35
+ add_line_to_tlds(line, tlds)
36
+ elsif line =~ /BEGIN PRIVATE/
37
+ in_private_tlds = true
38
+ end
39
+ end
58
40
  end
41
+ end
59
42
 
60
- def tld=(new_tld)
61
- self.host = "#{subdomain}.#{domain}.#{new_tld}"
43
+ def self.public_tlds
44
+ @public_tlds ||= {}.tap do |tlds|
45
+ with_tld_file do |line|
46
+ break if line =~ /END ICANN/
47
+ add_line_to_tlds(line, tlds)
48
+ end
62
49
  end
50
+ end
63
51
 
64
- private
65
- def query_hash_for(contents)
66
- hash = Addressabler::Query[contents]
67
- hash.uri = self
68
- hash
69
- end
52
+ def self.use_private_tlds=(new_use_private_tlds)
53
+ @use_private_tlds = new_use_private_tlds
54
+ end
70
55
 
71
- def parse_domain_parts
72
- tld = self.tld
73
- subdomain_parts = host.to_s.gsub(/\.#{tld}$/, '').split('.')
74
- @domain_parts = {
75
- :domain => subdomain_parts.pop,
76
- :subdomain => subdomain_parts.join('.'),
77
- :tld => tld
78
- }
79
- end
56
+ def self.use_private_tlds?
57
+ return @use_private_tlds if defined? @use_private_tlds
58
+ @use_private_tlds = false
80
59
  end
81
60
 
61
+ private # More for my own reference than anything else
62
+
82
63
  # Thanks Domainatrix for the parsing logic!
83
- tlds = {}
84
- File.readlines(File.join(File.dirname(__FILE__), 'tlds')).each do |line|
85
- line.strip!
64
+ def self.add_line_to_tlds(line, tlds)
65
+ line = line.to_s.strip
86
66
  unless line == '' || line =~ /^\//
87
67
  parts = line.split(".").reverse
88
68
  sub_hash = tlds
@@ -91,8 +71,40 @@ module Addressabler
91
71
  end
92
72
  end
93
73
  end
94
- TLDS = tlds
95
- end
96
74
 
97
- Addressable::URI.extend Addressabler::ClassMethods
98
- Addressable::URI.send :include, Addressabler::InstanceMethods
75
+ def self.const_missing(name)
76
+ if name.to_s == 'TLDS'
77
+ deprecation_warning "Addressabler::TLDS will be replaced by Addressabler::public_tlds and Addressabler::private_tlds in Addressable 1.0"
78
+ public_tlds
79
+ else
80
+ super
81
+ end
82
+ end
83
+
84
+ def self.deprecation_warning(message)
85
+ puts "ADDRESSABLER DEPRECATION WARNING: #{message}"
86
+ non_addressable_caller = caller.find do |line|
87
+ line !~ /#{File.expand_path(File.join(File.dirname(__FILE__), '..'))}/
88
+ end
89
+ if non_addressable_caller
90
+ puts " Called from:\n #{non_addressable_caller}"
91
+ end
92
+ end
93
+
94
+ def self.look_for_tld_in(sub_hash, host_parts)
95
+ tlds = []
96
+ while sub_hash = sub_hash[tld = host_parts.pop]
97
+ tlds.unshift(tld)
98
+ if sub_hash.has_key? '*'
99
+ tlds.unshift(host_parts.pop)
100
+ end
101
+ end
102
+ tlds
103
+ end
104
+
105
+ def self.with_tld_file
106
+ File.readlines(File.join(File.dirname(__FILE__), 'tlds')).each do |line|
107
+ yield line
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,238 @@
1
+ # coding: utf-8
2
+ # Copyright (C) 2006-2013 Bob Aman
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ require "spec_helper"
18
+
19
+ # Have to use RubyGems to load the idn gem.
20
+ require "rubygems"
21
+
22
+ require "addressable/idna"
23
+
24
+ shared_examples_for "converting from unicode to ASCII" do
25
+ it "should convert 'www.google.com' correctly" do
26
+ Addressable::IDNA.to_ascii("www.google.com").should == "www.google.com"
27
+ end
28
+
29
+ it "should convert 'www.詹姆斯.com' correctly" do
30
+ Addressable::IDNA.to_ascii(
31
+ "www.詹姆斯.com"
32
+ ).should == "www.xn--8ws00zhy3a.com"
33
+ end
34
+
35
+ it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
36
+ "www.Iñtërnâtiônàlizætiøn.com"
37
+ Addressable::IDNA.to_ascii(
38
+ "www.I\xC3\xB1t\xC3\xABrn\xC3\xA2ti\xC3\xB4" +
39
+ "n\xC3\xA0liz\xC3\xA6ti\xC3\xB8n.com"
40
+ ).should == "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
41
+ end
42
+
43
+ it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
44
+ Addressable::IDNA.to_ascii(
45
+ "www.In\xCC\x83te\xCC\x88rna\xCC\x82tio\xCC\x82n" +
46
+ "a\xCC\x80liz\xC3\xA6ti\xC3\xB8n.com"
47
+ ).should == "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
48
+ end
49
+
50
+ it "should convert " +
51
+ "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
52
+ "correctly" do
53
+ Addressable::IDNA.to_ascii(
54
+ "www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
55
+ "\201\252\343\201\214\343\201\204\343\202\217\343\201\221\343\201\256" +
56
+ "\343\202\217\343\201\213\343\202\211\343\201\252\343\201\204\343\201" +
57
+ "\251\343\202\201\343\201\204\343\202\223\343\202\201\343\201\204\343" +
58
+ "\201\256\343\202\211\343\201\271\343\202\213\343\201\276\343\201\240" +
59
+ "\343\201\252\343\201\214\343\201\217\343\201\227\343\201\252\343\201" +
60
+ "\204\343\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
61
+ "w3.mag.keio.ac.jp"
62
+ ).should ==
63
+ "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
64
+ "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
65
+ end
66
+
67
+ it "should convert " +
68
+ "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
69
+ "correctly" do
70
+ Addressable::IDNA.to_ascii(
71
+ "www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
72
+ "\201\252\343\201\213\343\202\231\343\201\204\343\202\217\343\201\221" +
73
+ "\343\201\256\343\202\217\343\201\213\343\202\211\343\201\252\343\201" +
74
+ "\204\343\201\250\343\202\231\343\202\201\343\201\204\343\202\223\343" +
75
+ "\202\201\343\201\204\343\201\256\343\202\211\343\201\270\343\202\231" +
76
+ "\343\202\213\343\201\276\343\201\237\343\202\231\343\201\252\343\201" +
77
+ "\213\343\202\231\343\201\217\343\201\227\343\201\252\343\201\204\343" +
78
+ "\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
79
+ "w3.mag.keio.ac.jp"
80
+ ).should ==
81
+ "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
82
+ "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
83
+ end
84
+
85
+ it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
86
+ Addressable::IDNA.to_ascii(
87
+ "点心和烤鸭.w3.mag.keio.ac.jp"
88
+ ).should == "xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
89
+ end
90
+
91
+ it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
92
+ Addressable::IDNA.to_ascii(
93
+ "가각갂갃간갅갆갇갈갉힢힣.com"
94
+ ).should == "xn--o39acdefghijk5883jma.com"
95
+ end
96
+
97
+ it "should convert " +
98
+ "'\347\242\274\346\250\231\346\272\226\350" +
99
+ "\220\254\345\234\213\347\242\274.com' correctly" do
100
+ Addressable::IDNA.to_ascii(
101
+ "\347\242\274\346\250\231\346\272\226\350" +
102
+ "\220\254\345\234\213\347\242\274.com"
103
+ ).should == "xn--9cs565brid46mda086o.com"
104
+ end
105
+
106
+ it "should convert 'リ宠퐱〹.com' correctly" do
107
+ Addressable::IDNA.to_ascii(
108
+ "\357\276\230\345\256\240\355\220\261\343\200\271.com"
109
+ ).should == "xn--eek174hoxfpr4k.com"
110
+ end
111
+
112
+ it "should convert 'リ宠퐱卄.com' correctly" do
113
+ Addressable::IDNA.to_ascii(
114
+ "\343\203\252\345\256\240\355\220\261\345\215\204.com"
115
+ ).should == "xn--eek174hoxfpr4k.com"
116
+ end
117
+
118
+ it "should convert 'ᆵ' correctly" do
119
+ Addressable::IDNA.to_ascii(
120
+ "\341\206\265"
121
+ ).should == "xn--4ud"
122
+ end
123
+
124
+ it "should convert 'ᆵ' correctly" do
125
+ Addressable::IDNA.to_ascii(
126
+ "\357\276\257"
127
+ ).should == "xn--4ud"
128
+ end
129
+ end
130
+
131
+ shared_examples_for "converting from ASCII to unicode" do
132
+ it "should convert 'www.google.com' correctly" do
133
+ Addressable::IDNA.to_unicode("www.google.com").should == "www.google.com"
134
+ end
135
+
136
+ it "should convert 'www.詹姆斯.com' correctly" do
137
+ Addressable::IDNA.to_unicode(
138
+ "www.xn--8ws00zhy3a.com"
139
+ ).should == "www.詹姆斯.com"
140
+ end
141
+
142
+ it "should convert 'www.iñtërnâtiônàlizætiøn.com' correctly" do
143
+ Addressable::IDNA.to_unicode(
144
+ "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
145
+ ).should == "www.iñtërnâtiônàlizætiøn.com"
146
+ end
147
+
148
+ it "should convert " +
149
+ "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
150
+ "correctly" do
151
+ Addressable::IDNA.to_unicode(
152
+ "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
153
+ "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
154
+ ).should ==
155
+ "www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp"
156
+ end
157
+
158
+ it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
159
+ Addressable::IDNA.to_unicode(
160
+ "xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
161
+ ).should == "点心和烤鸭.w3.mag.keio.ac.jp"
162
+ end
163
+
164
+ it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
165
+ Addressable::IDNA.to_unicode(
166
+ "xn--o39acdefghijk5883jma.com"
167
+ ).should == "가각갂갃간갅갆갇갈갉힢힣.com"
168
+ end
169
+
170
+ it "should convert " +
171
+ "'\347\242\274\346\250\231\346\272\226\350" +
172
+ "\220\254\345\234\213\347\242\274.com' correctly" do
173
+ Addressable::IDNA.to_unicode(
174
+ "xn--9cs565brid46mda086o.com"
175
+ ).should ==
176
+ "\347\242\274\346\250\231\346\272\226\350" +
177
+ "\220\254\345\234\213\347\242\274.com"
178
+ end
179
+
180
+ it "should convert 'リ宠퐱卄.com' correctly" do
181
+ Addressable::IDNA.to_unicode(
182
+ "xn--eek174hoxfpr4k.com"
183
+ ).should == "\343\203\252\345\256\240\355\220\261\345\215\204.com"
184
+ end
185
+
186
+ it "should convert 'ᆵ' correctly" do
187
+ Addressable::IDNA.to_unicode(
188
+ "xn--4ud"
189
+ ).should == "\341\206\265"
190
+ end
191
+
192
+ it "should normalize 'string' correctly" do
193
+ Addressable::IDNA.unicode_normalize_kc(:'string').should == "string"
194
+ Addressable::IDNA.unicode_normalize_kc("string").should == "string"
195
+ end
196
+ end
197
+
198
+ describe Addressable::IDNA, "when using the pure-Ruby implementation" do
199
+ before do
200
+ Addressable.send(:remove_const, :IDNA)
201
+ load "addressable/idna/pure.rb"
202
+ end
203
+
204
+ it_should_behave_like "converting from unicode to ASCII"
205
+ it_should_behave_like "converting from ASCII to unicode"
206
+
207
+ begin
208
+ require "fiber"
209
+
210
+ it "should not blow up inside fibers" do
211
+ f = Fiber.new do
212
+ Addressable.send(:remove_const, :IDNA)
213
+ load "addressable/idna/pure.rb"
214
+ end
215
+ f.resume
216
+ end
217
+ rescue LoadError
218
+ # Fibers aren't supported in this version of Ruby, skip this test.
219
+ warn('Fibers unsupported.')
220
+ end
221
+ end
222
+
223
+ begin
224
+ require "idn"
225
+
226
+ describe Addressable::IDNA, "when using the native-code implementation" do
227
+ before do
228
+ Addressable.send(:remove_const, :IDNA)
229
+ load "addressable/idna/native.rb"
230
+ end
231
+
232
+ it_should_behave_like "converting from unicode to ASCII"
233
+ it_should_behave_like "converting from ASCII to unicode"
234
+ end
235
+ rescue LoadError
236
+ # Cannot test the native implementation without libidn support.
237
+ warn('Could not load native IDN implementation.')
238
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ # Copyright (C) 2006-2013 Bob Aman
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+
17
+ require "spec_helper"
18
+
19
+ require "addressable/uri"
20
+ require "net/http"
21
+
22
+ describe Net::HTTP do
23
+ it "should be compatible with Addressable" do
24
+ response_body =
25
+ Net::HTTP.get(Addressable::URI.parse('http://www.google.com/'))
26
+ response_body.should_not be_nil
27
+ end
28
+ end