addressable 2.3.6 → 2.8.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.
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # encoding:utf-8
2
4
  #--
3
- # Copyright (C) 2006-2013 Bob Aman
5
+ # Copyright (C) Bob Aman
4
6
  #
5
7
  # Licensed under the Apache License, Version 2.0 (the "License");
6
8
  # you may not use this file except in compliance with the License.
@@ -21,8 +23,8 @@ if !defined?(Addressable::VERSION)
21
23
  module Addressable
22
24
  module VERSION
23
25
  MAJOR = 2
24
- MINOR = 3
25
- TINY = 6
26
+ MINOR = 8
27
+ TINY = 0
26
28
 
27
29
  STRING = [MAJOR, MINOR, TINY].join('.')
28
30
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable/uri'
4
+ require 'addressable/template'
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
- # Copyright (C) 2006-2013 Bob Aman
4
+ # Copyright (C) Bob Aman
3
5
  #
4
6
  # Licensed under the Apache License, Version 2.0 (the "License");
5
7
  # you may not use this file except in compliance with the License.
@@ -23,34 +25,39 @@ require "addressable/idna"
23
25
 
24
26
  shared_examples_for "converting from unicode to ASCII" do
25
27
  it "should convert 'www.google.com' correctly" do
26
- Addressable::IDNA.to_ascii("www.google.com").should == "www.google.com"
28
+ expect(Addressable::IDNA.to_ascii("www.google.com")).to eq("www.google.com")
29
+ end
30
+
31
+ long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
32
+ it "should convert '#{long}' correctly" do
33
+ expect(Addressable::IDNA.to_ascii(long)).to eq(long)
27
34
  end
28
35
 
29
36
  it "should convert 'www.詹姆斯.com' correctly" do
30
- Addressable::IDNA.to_ascii(
37
+ expect(Addressable::IDNA.to_ascii(
31
38
  "www.詹姆斯.com"
32
- ).should == "www.xn--8ws00zhy3a.com"
39
+ )).to eq("www.xn--8ws00zhy3a.com")
33
40
  end
34
41
 
35
42
  it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
36
43
  "www.Iñtërnâtiônàlizætiøn.com"
37
- Addressable::IDNA.to_ascii(
44
+ expect(Addressable::IDNA.to_ascii(
38
45
  "www.I\xC3\xB1t\xC3\xABrn\xC3\xA2ti\xC3\xB4" +
39
46
  "n\xC3\xA0liz\xC3\xA6ti\xC3\xB8n.com"
40
- ).should == "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
47
+ )).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
41
48
  end
42
49
 
43
50
  it "should convert 'www.Iñtërnâtiônàlizætiøn.com' correctly" do
44
- Addressable::IDNA.to_ascii(
51
+ expect(Addressable::IDNA.to_ascii(
45
52
  "www.In\xCC\x83te\xCC\x88rna\xCC\x82tio\xCC\x82n" +
46
53
  "a\xCC\x80liz\xC3\xA6ti\xC3\xB8n.com"
47
- ).should == "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
54
+ )).to eq("www.xn--itrntinliztin-vdb0a5exd8ewcye.com")
48
55
  end
49
56
 
50
57
  it "should convert " +
51
58
  "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
52
59
  "correctly" do
53
- Addressable::IDNA.to_ascii(
60
+ expect(Addressable::IDNA.to_ascii(
54
61
  "www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
55
62
  "\201\252\343\201\214\343\201\204\343\202\217\343\201\221\343\201\256" +
56
63
  "\343\202\217\343\201\213\343\202\211\343\201\252\343\201\204\343\201" +
@@ -59,15 +66,16 @@ shared_examples_for "converting from unicode to ASCII" do
59
66
  "\343\201\252\343\201\214\343\201\217\343\201\227\343\201\252\343\201" +
60
67
  "\204\343\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
61
68
  "w3.mag.keio.ac.jp"
62
- ).should ==
69
+ )).to eq(
63
70
  "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
64
71
  "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
72
+ )
65
73
  end
66
74
 
67
75
  it "should convert " +
68
76
  "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
69
77
  "correctly" do
70
- Addressable::IDNA.to_ascii(
78
+ expect(Addressable::IDNA.to_ascii(
71
79
  "www.\343\201\273\343\202\223\343\201\250\343\201\206\343\201\253\343" +
72
80
  "\201\252\343\201\213\343\202\231\343\201\204\343\202\217\343\201\221" +
73
81
  "\343\201\256\343\202\217\343\201\213\343\202\211\343\201\252\343\201" +
@@ -77,121 +85,175 @@ shared_examples_for "converting from unicode to ASCII" do
77
85
  "\213\343\202\231\343\201\217\343\201\227\343\201\252\343\201\204\343" +
78
86
  "\201\250\343\201\237\343\202\212\343\201\252\343\201\204." +
79
87
  "w3.mag.keio.ac.jp"
80
- ).should ==
88
+ )).to eq(
81
89
  "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
82
90
  "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
91
+ )
83
92
  end
84
93
 
85
94
  it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
86
- Addressable::IDNA.to_ascii(
95
+ expect(Addressable::IDNA.to_ascii(
87
96
  "点心和烤鸭.w3.mag.keio.ac.jp"
88
- ).should == "xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
97
+ )).to eq("xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp")
89
98
  end
90
99
 
91
100
  it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
92
- Addressable::IDNA.to_ascii(
101
+ expect(Addressable::IDNA.to_ascii(
93
102
  "가각갂갃간갅갆갇갈갉힢힣.com"
94
- ).should == "xn--o39acdefghijk5883jma.com"
103
+ )).to eq("xn--o39acdefghijk5883jma.com")
95
104
  end
96
105
 
97
106
  it "should convert " +
98
107
  "'\347\242\274\346\250\231\346\272\226\350" +
99
108
  "\220\254\345\234\213\347\242\274.com' correctly" do
100
- Addressable::IDNA.to_ascii(
109
+ expect(Addressable::IDNA.to_ascii(
101
110
  "\347\242\274\346\250\231\346\272\226\350" +
102
111
  "\220\254\345\234\213\347\242\274.com"
103
- ).should == "xn--9cs565brid46mda086o.com"
112
+ )).to eq("xn--9cs565brid46mda086o.com")
104
113
  end
105
114
 
106
115
  it "should convert 'リ宠퐱〹.com' correctly" do
107
- Addressable::IDNA.to_ascii(
116
+ expect(Addressable::IDNA.to_ascii(
108
117
  "\357\276\230\345\256\240\355\220\261\343\200\271.com"
109
- ).should == "xn--eek174hoxfpr4k.com"
118
+ )).to eq("xn--eek174hoxfpr4k.com")
110
119
  end
111
120
 
112
121
  it "should convert 'リ宠퐱卄.com' correctly" do
113
- Addressable::IDNA.to_ascii(
122
+ expect(Addressable::IDNA.to_ascii(
114
123
  "\343\203\252\345\256\240\355\220\261\345\215\204.com"
115
- ).should == "xn--eek174hoxfpr4k.com"
124
+ )).to eq("xn--eek174hoxfpr4k.com")
116
125
  end
117
126
 
118
127
  it "should convert 'ᆵ' correctly" do
119
- Addressable::IDNA.to_ascii(
128
+ expect(Addressable::IDNA.to_ascii(
120
129
  "\341\206\265"
121
- ).should == "xn--4ud"
130
+ )).to eq("xn--4ud")
122
131
  end
123
132
 
124
133
  it "should convert 'ᆵ' correctly" do
125
- Addressable::IDNA.to_ascii(
134
+ expect(Addressable::IDNA.to_ascii(
126
135
  "\357\276\257"
127
- ).should == "xn--4ud"
136
+ )).to eq("xn--4ud")
137
+ end
138
+
139
+ it "should convert '🌹🌹🌹.ws' correctly" do
140
+ expect(Addressable::IDNA.to_ascii(
141
+ "\360\237\214\271\360\237\214\271\360\237\214\271.ws"
142
+ )).to eq("xn--2h8haa.ws")
143
+ end
144
+
145
+ it "should handle two adjacent '.'s correctly" do
146
+ expect(Addressable::IDNA.to_ascii(
147
+ "example..host"
148
+ )).to eq("example..host")
128
149
  end
129
150
  end
130
151
 
131
152
  shared_examples_for "converting from ASCII to unicode" do
153
+ long = 'AcinusFallumTrompetumNullunCreditumVisumEstAtCuadLongumEtCefallum.com'
154
+ it "should convert '#{long}' correctly" do
155
+ expect(Addressable::IDNA.to_unicode(long)).to eq(long)
156
+ end
157
+
158
+ it "should return the identity conversion when punycode decode fails" do
159
+ expect(Addressable::IDNA.to_unicode("xn--zckp1cyg1.sblo.jp")).to eq(
160
+ "xn--zckp1cyg1.sblo.jp")
161
+ end
162
+
163
+ it "should return the identity conversion when the ACE prefix has no suffix" do
164
+ expect(Addressable::IDNA.to_unicode("xn--...-")).to eq("xn--...-")
165
+ end
166
+
132
167
  it "should convert 'www.google.com' correctly" do
133
- Addressable::IDNA.to_unicode("www.google.com").should == "www.google.com"
168
+ expect(Addressable::IDNA.to_unicode("www.google.com")).to eq(
169
+ "www.google.com")
134
170
  end
135
171
 
136
172
  it "should convert 'www.詹姆斯.com' correctly" do
137
- Addressable::IDNA.to_unicode(
173
+ expect(Addressable::IDNA.to_unicode(
138
174
  "www.xn--8ws00zhy3a.com"
139
- ).should == "www.詹姆斯.com"
175
+ )).to eq("www.詹姆斯.com")
176
+ end
177
+
178
+ it "should convert '詹姆斯.com' correctly" do
179
+ expect(Addressable::IDNA.to_unicode(
180
+ "xn--8ws00zhy3a.com"
181
+ )).to eq("詹姆斯.com")
140
182
  end
141
183
 
142
184
  it "should convert 'www.iñtërnâtiônàlizætiøn.com' correctly" do
143
- Addressable::IDNA.to_unicode(
185
+ expect(Addressable::IDNA.to_unicode(
144
186
  "www.xn--itrntinliztin-vdb0a5exd8ewcye.com"
145
- ).should == "www.iñtërnâtiônàlizætiøn.com"
187
+ )).to eq("www.iñtërnâtiônàlizætiøn.com")
188
+ end
189
+
190
+ it "should convert 'iñtërnâtiônàlizætiøn.com' correctly" do
191
+ expect(Addressable::IDNA.to_unicode(
192
+ "xn--itrntinliztin-vdb0a5exd8ewcye.com"
193
+ )).to eq("iñtërnâtiônàlizætiøn.com")
146
194
  end
147
195
 
148
196
  it "should convert " +
149
197
  "'www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp' " +
150
198
  "correctly" do
151
- Addressable::IDNA.to_unicode(
199
+ expect(Addressable::IDNA.to_unicode(
152
200
  "www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3" +
153
201
  "fg11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
154
- ).should ==
202
+ )).to eq(
155
203
  "www.ほんとうにながいわけのわからないどめいんめいのらべるまだながくしないとたりない.w3.mag.keio.ac.jp"
204
+ )
156
205
  end
157
206
 
158
207
  it "should convert '点心和烤鸭.w3.mag.keio.ac.jp' correctly" do
159
- Addressable::IDNA.to_unicode(
208
+ expect(Addressable::IDNA.to_unicode(
160
209
  "xn--0trv4xfvn8el34t.w3.mag.keio.ac.jp"
161
- ).should == "点心和烤鸭.w3.mag.keio.ac.jp"
210
+ )).to eq("点心和烤鸭.w3.mag.keio.ac.jp")
162
211
  end
163
212
 
164
213
  it "should convert '가각갂갃간갅갆갇갈갉힢힣.com' correctly" do
165
- Addressable::IDNA.to_unicode(
214
+ expect(Addressable::IDNA.to_unicode(
166
215
  "xn--o39acdefghijk5883jma.com"
167
- ).should == "가각갂갃간갅갆갇갈갉힢힣.com"
216
+ )).to eq("가각갂갃간갅갆갇갈갉힢힣.com")
168
217
  end
169
218
 
170
219
  it "should convert " +
171
220
  "'\347\242\274\346\250\231\346\272\226\350" +
172
221
  "\220\254\345\234\213\347\242\274.com' correctly" do
173
- Addressable::IDNA.to_unicode(
222
+ expect(Addressable::IDNA.to_unicode(
174
223
  "xn--9cs565brid46mda086o.com"
175
- ).should ==
224
+ )).to eq(
176
225
  "\347\242\274\346\250\231\346\272\226\350" +
177
226
  "\220\254\345\234\213\347\242\274.com"
227
+ )
178
228
  end
179
229
 
180
230
  it "should convert 'リ宠퐱卄.com' correctly" do
181
- Addressable::IDNA.to_unicode(
231
+ expect(Addressable::IDNA.to_unicode(
182
232
  "xn--eek174hoxfpr4k.com"
183
- ).should == "\343\203\252\345\256\240\355\220\261\345\215\204.com"
233
+ )).to eq("\343\203\252\345\256\240\355\220\261\345\215\204.com")
184
234
  end
185
235
 
186
236
  it "should convert 'ᆵ' correctly" do
187
- Addressable::IDNA.to_unicode(
237
+ expect(Addressable::IDNA.to_unicode(
188
238
  "xn--4ud"
189
- ).should == "\341\206\265"
239
+ )).to eq("\341\206\265")
240
+ end
241
+
242
+ it "should convert '🌹🌹🌹.ws' correctly" do
243
+ expect(Addressable::IDNA.to_unicode(
244
+ "xn--2h8haa.ws"
245
+ )).to eq("\360\237\214\271\360\237\214\271\360\237\214\271.ws")
246
+ end
247
+
248
+ it "should handle two adjacent '.'s correctly" do
249
+ expect(Addressable::IDNA.to_unicode(
250
+ "example..host"
251
+ )).to eq("example..host")
190
252
  end
191
253
 
192
254
  it "should normalize 'string' correctly" do
193
- Addressable::IDNA.unicode_normalize_kc(:'string').should == "string"
194
- Addressable::IDNA.unicode_normalize_kc("string").should == "string"
255
+ expect(Addressable::IDNA.unicode_normalize_kc(:'string')).to eq("string")
256
+ expect(Addressable::IDNA.unicode_normalize_kc("string")).to eq("string")
195
257
  end
196
258
  end
197
259
 
@@ -232,7 +294,9 @@ begin
232
294
  it_should_behave_like "converting from unicode to ASCII"
233
295
  it_should_behave_like "converting from ASCII to unicode"
234
296
  end
235
- rescue LoadError
297
+ rescue LoadError => error
298
+ raise error if ENV["CI"] && TestHelper.native_supported?
299
+
236
300
  # Cannot test the native implementation without libidn support.
237
301
  warn('Could not load native IDN implementation.')
238
302
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
- # Copyright (C) 2006-2013 Bob Aman
4
+ # Copyright (C) Bob Aman
3
5
  #
4
6
  # Licensed under the Apache License, Version 2.0 (the "License");
5
7
  # you may not use this file except in compliance with the License.
@@ -23,6 +25,6 @@ describe Net::HTTP do
23
25
  it "should be compatible with Addressable" do
24
26
  response_body =
25
27
  Net::HTTP.get(Addressable::URI.parse('http://www.google.com/'))
26
- response_body.should_not be_nil
28
+ expect(response_body).not_to be_nil
27
29
  end
28
30
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # coding: utf-8
4
+ # Copyright (C) Bob Aman
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+
18
+
19
+ require "spec_helper"
20
+
21
+ require "addressable/uri"
22
+
23
+ describe Addressable::URI, "when created with a URI known to cause crashes " +
24
+ "in certain browsers" do
25
+ it "should parse correctly" do
26
+ uri = Addressable::URI.parse('%%30%30')
27
+ expect(uri.path).to eq('%%30%30')
28
+ expect(uri.normalize.path).to eq('%2500')
29
+ end
30
+
31
+ it "should parse correctly as a full URI" do
32
+ uri = Addressable::URI.parse('http://www.example.com/%%30%30')
33
+ expect(uri.path).to eq('/%%30%30')
34
+ expect(uri.normalize.path).to eq('/%2500')
35
+ end
36
+ end
37
+
38
+ describe Addressable::URI, "when created with a URI known to cause crashes " +
39
+ "in certain browsers" do
40
+ it "should parse correctly" do
41
+ uri = Addressable::URI.parse('لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
42
+ expect(uri.path).to eq('لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
43
+ expect(uri.normalize.path).to eq(
44
+ '%D9%84%D9%8F%D8%B5%D9%91%D8%A8%D9%8F%D9%84%D9%8F%D9%84%D8%B5%D9%91' +
45
+ '%D8%A8%D9%8F%D8%B1%D8%B1%D9%8B%20%E0%A5%A3%20%E0%A5%A3h%20%E0%A5' +
46
+ '%A3%20%E0%A5%A3%20%E5%86%97'
47
+ )
48
+ end
49
+
50
+ it "should parse correctly as a full URI" do
51
+ uri = Addressable::URI.parse('http://www.example.com/لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
52
+ expect(uri.path).to eq('/لُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ 冗')
53
+ expect(uri.normalize.path).to eq(
54
+ '/%D9%84%D9%8F%D8%B5%D9%91%D8%A8%D9%8F%D9%84%D9%8F%D9%84%D8%B5%D9%91' +
55
+ '%D8%A8%D9%8F%D8%B1%D8%B1%D9%8B%20%E0%A5%A3%20%E0%A5%A3h%20%E0%A5' +
56
+ '%A3%20%E0%A5%A3%20%E5%86%97'
57
+ )
58
+ end
59
+ end