addressabler 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.markdown +1 -1
- data/lib/addressabler.rb +2 -1
- data/lib/tlds +3296 -252
- data/spec/addressabler_spec.rb +30 -17
- data/spec/uri_spec.rb +1076 -125
- metadata +68 -66
data/spec/uri_spec.rb
CHANGED
@@ -1,4 +1,19 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
# Copyright (C) 2006-2011 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
|
+
|
2
17
|
require "addressable/uri"
|
3
18
|
|
4
19
|
if !"".respond_to?("force_encoding")
|
@@ -135,6 +150,14 @@ describe Addressable::URI, "when created with a scheme but no hierarchical " +
|
|
135
150
|
end
|
136
151
|
end
|
137
152
|
|
153
|
+
describe Addressable::URI, "when created with an invalid host" do
|
154
|
+
it "should raise an error" do
|
155
|
+
(lambda do
|
156
|
+
Addressable::URI.new(:host => "<invalid>")
|
157
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
138
161
|
describe Addressable::URI, "when created from nil components" do
|
139
162
|
before do
|
140
163
|
@uri = Addressable::URI.new
|
@@ -152,6 +175,10 @@ describe Addressable::URI, "when created from nil components" do
|
|
152
175
|
@uri.to_s.should == ""
|
153
176
|
end
|
154
177
|
|
178
|
+
it "should have a nil default port" do
|
179
|
+
@uri.default_port.should == nil
|
180
|
+
end
|
181
|
+
|
155
182
|
it "should raise an error if the scheme is set to whitespace" do
|
156
183
|
(lambda do
|
157
184
|
@uri.scheme = "\t \n"
|
@@ -191,6 +218,112 @@ describe Addressable::URI, "when created from nil components" do
|
|
191
218
|
end
|
192
219
|
end
|
193
220
|
|
221
|
+
describe Addressable::URI, "when frozen" do
|
222
|
+
before do
|
223
|
+
@uri = Addressable::URI.new.freeze
|
224
|
+
end
|
225
|
+
|
226
|
+
it "returns nil for #scheme" do
|
227
|
+
@uri.scheme.should == nil
|
228
|
+
end
|
229
|
+
|
230
|
+
it "returns nil for #normalized_scheme" do
|
231
|
+
@uri.normalized_scheme.should == nil
|
232
|
+
end
|
233
|
+
|
234
|
+
it "returns nil for #user" do
|
235
|
+
@uri.user .should == nil
|
236
|
+
end
|
237
|
+
|
238
|
+
it "returns nil for #normalized_user" do
|
239
|
+
@uri.normalized_user.should == nil
|
240
|
+
end
|
241
|
+
|
242
|
+
it "returns nil for #password" do
|
243
|
+
@uri.password.should == nil
|
244
|
+
end
|
245
|
+
|
246
|
+
it "returns nil for #normalized_password" do
|
247
|
+
@uri.normalized_password.should == nil
|
248
|
+
end
|
249
|
+
|
250
|
+
it "returns nil for #userinfo" do
|
251
|
+
@uri.userinfo.should == nil
|
252
|
+
end
|
253
|
+
|
254
|
+
it "returns nil for #normalized_userinfo" do
|
255
|
+
@uri.normalized_userinfo.should == nil
|
256
|
+
end
|
257
|
+
|
258
|
+
it "returns nil for #host" do
|
259
|
+
@uri.host.should == nil
|
260
|
+
end
|
261
|
+
|
262
|
+
it "returns nil for #normalized_host" do
|
263
|
+
@uri.normalized_host.should == nil
|
264
|
+
end
|
265
|
+
|
266
|
+
it "returns nil for #authority" do
|
267
|
+
@uri.authority.should == nil
|
268
|
+
end
|
269
|
+
|
270
|
+
it "returns nil for #normalized_authority" do
|
271
|
+
@uri.normalized_authority.should == nil
|
272
|
+
end
|
273
|
+
|
274
|
+
it "returns nil for #port" do
|
275
|
+
@uri.port.should == nil
|
276
|
+
end
|
277
|
+
|
278
|
+
it "returns nil for #normalized_port" do
|
279
|
+
@uri.normalized_port.should == nil
|
280
|
+
end
|
281
|
+
|
282
|
+
it "returns nil for #default_port" do
|
283
|
+
@uri.default_port.should == nil
|
284
|
+
end
|
285
|
+
|
286
|
+
it "returns nil for #site" do
|
287
|
+
@uri.site.should == nil
|
288
|
+
end
|
289
|
+
|
290
|
+
it "returns nil for #normalized_site" do
|
291
|
+
@uri.normalized_site.should == nil
|
292
|
+
end
|
293
|
+
|
294
|
+
it "returns '' for #path" do
|
295
|
+
@uri.path.should == ''
|
296
|
+
end
|
297
|
+
|
298
|
+
it "returns '' for #normalized_path" do
|
299
|
+
@uri.normalized_path.should == ''
|
300
|
+
end
|
301
|
+
|
302
|
+
it "returns nil for #query" do
|
303
|
+
@uri.query.should == nil
|
304
|
+
end
|
305
|
+
|
306
|
+
it "returns nil for #normalized_query" do
|
307
|
+
@uri.normalized_query.should == nil
|
308
|
+
end
|
309
|
+
|
310
|
+
it "returns nil for #fragment" do
|
311
|
+
@uri.fragment.should == nil
|
312
|
+
end
|
313
|
+
|
314
|
+
it "returns nil for #normalized_fragment" do
|
315
|
+
@uri.normalized_fragment.should == nil
|
316
|
+
end
|
317
|
+
|
318
|
+
it "returns #hash" do
|
319
|
+
@uri.hash.should_not be nil
|
320
|
+
end
|
321
|
+
|
322
|
+
it "returns #to_s" do
|
323
|
+
@uri.to_s.should == ''
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
194
327
|
describe Addressable::URI, "when created from string components" do
|
195
328
|
before do
|
196
329
|
@uri = Addressable::URI.new(
|
@@ -242,12 +375,17 @@ describe Addressable::URI, "when created with an authority and no port" do
|
|
242
375
|
|
243
376
|
it "should not infer a port" do
|
244
377
|
@uri.port.should == nil
|
378
|
+
@uri.default_port.should == nil
|
245
379
|
@uri.inferred_port.should == nil
|
246
380
|
end
|
247
381
|
|
248
382
|
it "should have a site value of '//user@example.com'" do
|
249
383
|
@uri.site.should == "//user@example.com"
|
250
384
|
end
|
385
|
+
|
386
|
+
it "should have a 'null' origin" do
|
387
|
+
@uri.origin.should == 'null'
|
388
|
+
end
|
251
389
|
end
|
252
390
|
|
253
391
|
describe Addressable::URI, "when created with both a userinfo and a user" do
|
@@ -273,6 +411,10 @@ describe Addressable::URI, "when created with a path that hasn't been " +
|
|
273
411
|
it "should have a site value of 'http://example.com'" do
|
274
412
|
@uri.site.should == "http://example.com"
|
275
413
|
end
|
414
|
+
|
415
|
+
it "should have an origin of 'http://example.com" do
|
416
|
+
@uri.origin.should == 'http://example.com'
|
417
|
+
end
|
276
418
|
end
|
277
419
|
|
278
420
|
describe Addressable::URI, "when created with a path that hasn't been " +
|
@@ -286,25 +428,35 @@ describe Addressable::URI, "when created with a path that hasn't been " +
|
|
286
428
|
it "should not prefix a '/' to the path" do
|
287
429
|
@uri.should == Addressable::URI.parse("http:path")
|
288
430
|
end
|
289
|
-
|
431
|
+
|
290
432
|
it "should have a site value of 'http:'" do
|
291
433
|
@uri.site.should == "http:"
|
292
434
|
end
|
435
|
+
|
436
|
+
it "should have a 'null' origin" do
|
437
|
+
@uri.origin.should == 'null'
|
438
|
+
end
|
293
439
|
end
|
294
440
|
|
295
441
|
describe Addressable::URI, "when parsed from an Addressable::URI object" do
|
296
|
-
it "should
|
297
|
-
|
298
|
-
(
|
299
|
-
|
300
|
-
|
442
|
+
it "should not have unexpected side-effects" do
|
443
|
+
original_uri = Addressable::URI.parse("http://example.com/")
|
444
|
+
new_uri = Addressable::URI.parse(original_uri)
|
445
|
+
new_uri.host = 'www.example.com'
|
446
|
+
new_uri.host.should == 'www.example.com'
|
447
|
+
new_uri.to_s.should == 'http://www.example.com/'
|
448
|
+
original_uri.host.should == 'example.com'
|
449
|
+
original_uri.to_s.should == 'http://example.com/'
|
301
450
|
end
|
302
451
|
|
303
|
-
it "should
|
304
|
-
|
305
|
-
(
|
306
|
-
|
307
|
-
|
452
|
+
it "should not have unexpected side-effects" do
|
453
|
+
original_uri = Addressable::URI.parse("http://example.com/")
|
454
|
+
new_uri = Addressable::URI.heuristic_parse(original_uri)
|
455
|
+
new_uri.host = 'www.example.com'
|
456
|
+
new_uri.host.should == 'www.example.com'
|
457
|
+
new_uri.to_s.should == 'http://www.example.com/'
|
458
|
+
original_uri.host.should == 'example.com'
|
459
|
+
original_uri.to_s.should == 'http://example.com/'
|
308
460
|
end
|
309
461
|
end
|
310
462
|
|
@@ -346,6 +498,10 @@ describe Addressable::URI, "when parsed from ''" do
|
|
346
498
|
it "should be considered to be in normal form" do
|
347
499
|
@uri.normalize.should be_eql(@uri)
|
348
500
|
end
|
501
|
+
|
502
|
+
it "should have a 'null' origin" do
|
503
|
+
@uri.origin.should == 'null'
|
504
|
+
end
|
349
505
|
end
|
350
506
|
|
351
507
|
# Section 1.1.2 of RFC 3986
|
@@ -367,6 +523,10 @@ describe Addressable::URI, "when parsed from " +
|
|
367
523
|
@uri.host.should == "ftp.is.co.za"
|
368
524
|
end
|
369
525
|
|
526
|
+
it "should have inferred_port of 21" do
|
527
|
+
@uri.inferred_port.should == 21
|
528
|
+
end
|
529
|
+
|
370
530
|
it "should have a path of '/rfc/rfc1808.txt'" do
|
371
531
|
@uri.path.should == "/rfc/rfc1808.txt"
|
372
532
|
end
|
@@ -378,6 +538,10 @@ describe Addressable::URI, "when parsed from " +
|
|
378
538
|
it "should be considered to be in normal form" do
|
379
539
|
@uri.normalize.should be_eql(@uri)
|
380
540
|
end
|
541
|
+
|
542
|
+
it "should have an origin of 'ftp://ftp.is.co.za'" do
|
543
|
+
@uri.origin.should == 'ftp://ftp.is.co.za'
|
544
|
+
end
|
381
545
|
end
|
382
546
|
|
383
547
|
# Section 1.1.2 of RFC 3986
|
@@ -399,6 +563,10 @@ describe Addressable::URI, "when parsed from " +
|
|
399
563
|
@uri.host.should == "www.ietf.org"
|
400
564
|
end
|
401
565
|
|
566
|
+
it "should have inferred_port of 80" do
|
567
|
+
@uri.inferred_port.should == 80
|
568
|
+
end
|
569
|
+
|
402
570
|
it "should have a path of '/rfc/rfc2396.txt'" do
|
403
571
|
@uri.path.should == "/rfc/rfc2396.txt"
|
404
572
|
end
|
@@ -420,6 +588,10 @@ describe Addressable::URI, "when parsed from " +
|
|
420
588
|
@uri.omit!(:scheme)
|
421
589
|
@uri.to_s.should == "//www.ietf.org/rfc/rfc2396.txt"
|
422
590
|
end
|
591
|
+
|
592
|
+
it "should have an origin of 'http://www.ietf.org'" do
|
593
|
+
@uri.origin.should == 'http://www.ietf.org'
|
594
|
+
end
|
423
595
|
end
|
424
596
|
|
425
597
|
# Section 1.1.2 of RFC 3986
|
@@ -441,6 +613,10 @@ describe Addressable::URI, "when parsed from " +
|
|
441
613
|
@uri.host.should == "[2001:db8::7]"
|
442
614
|
end
|
443
615
|
|
616
|
+
it "should have inferred_port of 389" do
|
617
|
+
@uri.inferred_port.should == 389
|
618
|
+
end
|
619
|
+
|
444
620
|
it "should have a path of '/c=GB'" do
|
445
621
|
@uri.path.should == "/c=GB"
|
446
622
|
end
|
@@ -478,6 +654,10 @@ describe Addressable::URI, "when parsed from " +
|
|
478
654
|
@uri.omit(:authority, :path)
|
479
655
|
end).should raise_error(Addressable::URI::InvalidURIError)
|
480
656
|
end
|
657
|
+
|
658
|
+
it "should have an origin of 'ldap://[2001:db8::7]'" do
|
659
|
+
@uri.origin.should == 'ldap://[2001:db8::7]'
|
660
|
+
end
|
481
661
|
end
|
482
662
|
|
483
663
|
# Section 1.1.2 of RFC 3986
|
@@ -495,6 +675,10 @@ describe Addressable::URI, "when parsed from " +
|
|
495
675
|
@uri.should_not be_ip_based
|
496
676
|
end
|
497
677
|
|
678
|
+
it "should not have an inferred_port" do
|
679
|
+
@uri.inferred_port.should == nil
|
680
|
+
end
|
681
|
+
|
498
682
|
it "should have a path of 'John.Doe@example.com'" do
|
499
683
|
@uri.path.should == "John.Doe@example.com"
|
500
684
|
end
|
@@ -506,6 +690,10 @@ describe Addressable::URI, "when parsed from " +
|
|
506
690
|
it "should be considered to be in normal form" do
|
507
691
|
@uri.normalize.should be_eql(@uri)
|
508
692
|
end
|
693
|
+
|
694
|
+
it "should have a 'null' origin" do
|
695
|
+
@uri.origin.should == 'null'
|
696
|
+
end
|
509
697
|
end
|
510
698
|
|
511
699
|
# Section 1.1.2 of RFC 3986
|
@@ -519,6 +707,10 @@ describe Addressable::URI, "when parsed from " +
|
|
519
707
|
@uri.scheme.should == "news"
|
520
708
|
end
|
521
709
|
|
710
|
+
it "should not have an inferred_port" do
|
711
|
+
@uri.inferred_port.should == nil
|
712
|
+
end
|
713
|
+
|
522
714
|
it "should not be considered to be ip-based" do
|
523
715
|
@uri.should_not be_ip_based
|
524
716
|
end
|
@@ -534,6 +726,10 @@ describe Addressable::URI, "when parsed from " +
|
|
534
726
|
it "should be considered to be in normal form" do
|
535
727
|
@uri.normalize.should be_eql(@uri)
|
536
728
|
end
|
729
|
+
|
730
|
+
it "should have a 'null' origin" do
|
731
|
+
@uri.origin.should == 'null'
|
732
|
+
end
|
537
733
|
end
|
538
734
|
|
539
735
|
# Section 1.1.2 of RFC 3986
|
@@ -551,6 +747,10 @@ describe Addressable::URI, "when parsed from " +
|
|
551
747
|
@uri.should_not be_ip_based
|
552
748
|
end
|
553
749
|
|
750
|
+
it "should not have an inferred_port" do
|
751
|
+
@uri.inferred_port.should == nil
|
752
|
+
end
|
753
|
+
|
554
754
|
it "should have a path of '+1-816-555-1212'" do
|
555
755
|
@uri.path.should == "+1-816-555-1212"
|
556
756
|
end
|
@@ -562,6 +762,10 @@ describe Addressable::URI, "when parsed from " +
|
|
562
762
|
it "should be considered to be in normal form" do
|
563
763
|
@uri.normalize.should be_eql(@uri)
|
564
764
|
end
|
765
|
+
|
766
|
+
it "should have a 'null' origin" do
|
767
|
+
@uri.origin.should == 'null'
|
768
|
+
end
|
565
769
|
end
|
566
770
|
|
567
771
|
# Section 1.1.2 of RFC 3986
|
@@ -579,10 +783,18 @@ describe Addressable::URI, "when parsed from " +
|
|
579
783
|
@uri.host.should == "192.0.2.16"
|
580
784
|
end
|
581
785
|
|
582
|
-
it "should have a port of
|
786
|
+
it "should have a port of 80" do
|
583
787
|
@uri.port.should == 80
|
584
788
|
end
|
585
789
|
|
790
|
+
it "should have a inferred_port of 80" do
|
791
|
+
@uri.inferred_port.should == 80
|
792
|
+
end
|
793
|
+
|
794
|
+
it "should have a default_port of 23" do
|
795
|
+
@uri.default_port.should == 23
|
796
|
+
end
|
797
|
+
|
586
798
|
it "should be considered to be ip-based" do
|
587
799
|
@uri.should be_ip_based
|
588
800
|
end
|
@@ -598,6 +810,10 @@ describe Addressable::URI, "when parsed from " +
|
|
598
810
|
it "should be considered to be in normal form" do
|
599
811
|
@uri.normalize.should be_eql(@uri)
|
600
812
|
end
|
813
|
+
|
814
|
+
it "should have an origin of 'telnet://192.0.2.16:80'" do
|
815
|
+
@uri.origin.should == 'telnet://192.0.2.16:80'
|
816
|
+
end
|
601
817
|
end
|
602
818
|
|
603
819
|
# Section 1.1.2 of RFC 3986
|
@@ -612,6 +828,10 @@ describe Addressable::URI, "when parsed from " +
|
|
612
828
|
@uri.scheme.should == "urn"
|
613
829
|
end
|
614
830
|
|
831
|
+
it "should not have an inferred_port" do
|
832
|
+
@uri.inferred_port.should == nil
|
833
|
+
end
|
834
|
+
|
615
835
|
it "should not be considered to be ip-based" do
|
616
836
|
@uri.should_not be_ip_based
|
617
837
|
end
|
@@ -628,6 +848,45 @@ describe Addressable::URI, "when parsed from " +
|
|
628
848
|
it "should be considered to be in normal form" do
|
629
849
|
@uri.normalize.should be_eql(@uri)
|
630
850
|
end
|
851
|
+
|
852
|
+
it "should have a 'null' origin" do
|
853
|
+
@uri.origin.should == 'null'
|
854
|
+
end
|
855
|
+
end
|
856
|
+
|
857
|
+
describe Addressable::URI, "when heuristically parsed from " +
|
858
|
+
"'192.0.2.16:8000/path'" do
|
859
|
+
before do
|
860
|
+
@uri = Addressable::URI.heuristic_parse("192.0.2.16:8000/path")
|
861
|
+
end
|
862
|
+
|
863
|
+
it "should use the 'http' scheme" do
|
864
|
+
@uri.scheme.should == "http"
|
865
|
+
end
|
866
|
+
|
867
|
+
it "should have a host of '192.0.2.16'" do
|
868
|
+
@uri.host.should == "192.0.2.16"
|
869
|
+
end
|
870
|
+
|
871
|
+
it "should have a port of '8000'" do
|
872
|
+
@uri.port.should == 8000
|
873
|
+
end
|
874
|
+
|
875
|
+
it "should be considered to be ip-based" do
|
876
|
+
@uri.should be_ip_based
|
877
|
+
end
|
878
|
+
|
879
|
+
it "should have a path of '/path'" do
|
880
|
+
@uri.path.should == "/path"
|
881
|
+
end
|
882
|
+
|
883
|
+
it "should be considered to be in normal form" do
|
884
|
+
@uri.normalize.should be_eql(@uri)
|
885
|
+
end
|
886
|
+
|
887
|
+
it "should have an origin of 'http://192.0.2.16:8000'" do
|
888
|
+
@uri.origin.should == 'http://192.0.2.16:8000'
|
889
|
+
end
|
631
890
|
end
|
632
891
|
|
633
892
|
describe Addressable::URI, "when parsed from " +
|
@@ -842,11 +1101,11 @@ describe Addressable::URI, "when parsed from " +
|
|
842
1101
|
end
|
843
1102
|
|
844
1103
|
it "should have the correct password after assignment" do
|
845
|
-
@uri.password = "secret@123!"
|
846
|
-
@uri.password.should == "secret@123!"
|
847
|
-
@uri.normalized_password.should == "
|
1104
|
+
@uri.password = "#secret@123!"
|
1105
|
+
@uri.password.should == "#secret@123!"
|
1106
|
+
@uri.normalized_password.should == "%23secret%40123%21"
|
848
1107
|
@uri.user.should == ""
|
849
|
-
@uri.normalize.to_s.should == "http
|
1108
|
+
@uri.normalize.to_s.should == "http://:%23secret%40123%21@example.com/"
|
850
1109
|
@uri.omit(:password).to_s.should == "http://example.com"
|
851
1110
|
end
|
852
1111
|
|
@@ -903,6 +1162,10 @@ describe Addressable::URI, "when parsed from " +
|
|
903
1162
|
it "should be identical to its duplicate" do
|
904
1163
|
@uri.should == @uri.dup
|
905
1164
|
end
|
1165
|
+
|
1166
|
+
it "should have an origin of 'http://example.com'" do
|
1167
|
+
@uri.origin.should == 'http://example.com'
|
1168
|
+
end
|
906
1169
|
end
|
907
1170
|
|
908
1171
|
# Section 5.1.2 of RFC 2616
|
@@ -954,6 +1217,78 @@ describe Addressable::URI, "when parsed from " +
|
|
954
1217
|
:fragment => nil
|
955
1218
|
}
|
956
1219
|
end
|
1220
|
+
|
1221
|
+
it "should have an origin of 'http://www.w3.org'" do
|
1222
|
+
@uri.origin.should == 'http://www.w3.org'
|
1223
|
+
end
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
describe Addressable::URI, "when parsing IPv6 addresses" do
|
1227
|
+
it "should not raise an error for " +
|
1228
|
+
"'http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
|
1229
|
+
Addressable::URI.parse("http://[3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
|
1230
|
+
end
|
1231
|
+
|
1232
|
+
it "should not raise an error for " +
|
1233
|
+
"'http://[fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
|
1234
|
+
Addressable::URI.parse("http://[fe80:0:0:0:200:f8ff:fe21:67cf]/")
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
it "should not raise an error for " +
|
1238
|
+
"'http://[fe80::200:f8ff:fe21:67cf]/'" do
|
1239
|
+
Addressable::URI.parse("http://[fe80::200:f8ff:fe21:67cf]/")
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
it "should not raise an error for " +
|
1243
|
+
"'http://[::1]/'" do
|
1244
|
+
Addressable::URI.parse("http://[::1]/")
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
it "should not raise an error for " +
|
1248
|
+
"'http://[fe80::1]/'" do
|
1249
|
+
Addressable::URI.parse("http://[fe80::1]/")
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
it "should raise an error for " +
|
1253
|
+
"'http://[<invalid>]/'" do
|
1254
|
+
(lambda do
|
1255
|
+
Addressable::URI.parse("http://[<invalid>]/")
|
1256
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
1257
|
+
end
|
1258
|
+
end
|
1259
|
+
|
1260
|
+
describe Addressable::URI, "when parsing IPvFuture addresses" do
|
1261
|
+
it "should not raise an error for " +
|
1262
|
+
"'http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/'" do
|
1263
|
+
Addressable::URI.parse("http://[v9.3ffe:1900:4545:3:200:f8ff:fe21:67cf]/")
|
1264
|
+
end
|
1265
|
+
|
1266
|
+
it "should not raise an error for " +
|
1267
|
+
"'http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/'" do
|
1268
|
+
Addressable::URI.parse("http://[vff.fe80:0:0:0:200:f8ff:fe21:67cf]/")
|
1269
|
+
end
|
1270
|
+
|
1271
|
+
it "should not raise an error for " +
|
1272
|
+
"'http://[v12.fe80::200:f8ff:fe21:67cf]/'" do
|
1273
|
+
Addressable::URI.parse("http://[v12.fe80::200:f8ff:fe21:67cf]/")
|
1274
|
+
end
|
1275
|
+
|
1276
|
+
it "should not raise an error for " +
|
1277
|
+
"'http://[va0.::1]/'" do
|
1278
|
+
Addressable::URI.parse("http://[va0.::1]/")
|
1279
|
+
end
|
1280
|
+
|
1281
|
+
it "should not raise an error for " +
|
1282
|
+
"'http://[v255.fe80::1]/'" do
|
1283
|
+
Addressable::URI.parse("http://[v255.fe80::1]/")
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
it "should raise an error for " +
|
1287
|
+
"'http://[v0.<invalid>]/'" do
|
1288
|
+
(lambda do
|
1289
|
+
Addressable::URI.parse("http://[v0.<invalid>]/")
|
1290
|
+
end).should raise_error(Addressable::URI::InvalidURIError)
|
1291
|
+
end
|
957
1292
|
end
|
958
1293
|
|
959
1294
|
describe Addressable::URI, "when parsed from " +
|
@@ -1069,6 +1404,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1069
1404
|
it "should have a different hash from http://example.com" do
|
1070
1405
|
@uri.hash.should_not == Addressable::URI.parse("http://example.com").hash
|
1071
1406
|
end
|
1407
|
+
|
1408
|
+
it "should have an origin of 'http://example.com'" do
|
1409
|
+
@uri.origin.should == 'http://example.com'
|
1410
|
+
end
|
1072
1411
|
end
|
1073
1412
|
|
1074
1413
|
describe Addressable::URI, "when parsed from " +
|
@@ -1097,6 +1436,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1097
1436
|
it "should be identical to its duplicate" do
|
1098
1437
|
@uri.should == @uri.dup
|
1099
1438
|
end
|
1439
|
+
|
1440
|
+
it "should have an origin of 'http://example.com'" do
|
1441
|
+
@uri.origin.should == 'http://example.com'
|
1442
|
+
end
|
1100
1443
|
end
|
1101
1444
|
|
1102
1445
|
describe Addressable::URI, "when parsed from " +
|
@@ -1116,6 +1459,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1116
1459
|
it "should be identical to its duplicate" do
|
1117
1460
|
@uri.should == @uri.dup
|
1118
1461
|
end
|
1462
|
+
|
1463
|
+
it "should have an origin of 'http://example.com'" do
|
1464
|
+
@uri.origin.should == 'http://example.com'
|
1465
|
+
end
|
1119
1466
|
end
|
1120
1467
|
|
1121
1468
|
describe Addressable::URI, "when parsed from " +
|
@@ -1144,6 +1491,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1144
1491
|
it "should be identical to its duplicate" do
|
1145
1492
|
@uri.should == @uri.dup
|
1146
1493
|
end
|
1494
|
+
|
1495
|
+
it "should have an origin of 'http://example.com'" do
|
1496
|
+
@uri.origin.should == 'http://example.com'
|
1497
|
+
end
|
1147
1498
|
end
|
1148
1499
|
|
1149
1500
|
describe Addressable::URI, "when parsed from " +
|
@@ -1398,6 +1749,10 @@ describe Addressable::URI, "when parsed from " +
|
|
1398
1749
|
end
|
1399
1750
|
|
1400
1751
|
it "should use port 80" do
|
1752
|
+
@uri.inferred_port.should == 80
|
1753
|
+
end
|
1754
|
+
|
1755
|
+
it "should have explicit port 80" do
|
1401
1756
|
@uri.port.should == 80
|
1402
1757
|
end
|
1403
1758
|
|
@@ -1481,6 +1836,17 @@ describe Addressable::URI, "when parsed from " +
|
|
1481
1836
|
it "should be identical to its duplicate" do
|
1482
1837
|
@uri.should == @uri.dup
|
1483
1838
|
end
|
1839
|
+
|
1840
|
+
it "should have an origin of 'http://example.com'" do
|
1841
|
+
@uri.origin.should == 'http://example.com'
|
1842
|
+
end
|
1843
|
+
|
1844
|
+
it "should not change if encoded with the normalizing algorithm" do
|
1845
|
+
Addressable::URI.normalized_encode(@uri).to_s.should ==
|
1846
|
+
"http://example.com:80/"
|
1847
|
+
Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
|
1848
|
+
"http://example.com:80/"
|
1849
|
+
end
|
1484
1850
|
end
|
1485
1851
|
|
1486
1852
|
describe Addressable::URI, "when parsed from " +
|
@@ -1510,9 +1876,17 @@ describe Addressable::URI, "when parsed from " +
|
|
1510
1876
|
end
|
1511
1877
|
|
1512
1878
|
it "should use port 8080" do
|
1879
|
+
@uri.inferred_port.should == 8080
|
1880
|
+
end
|
1881
|
+
|
1882
|
+
it "should have explicit port 8080" do
|
1513
1883
|
@uri.port.should == 8080
|
1514
1884
|
end
|
1515
1885
|
|
1886
|
+
it "should have default port 80" do
|
1887
|
+
@uri.default_port.should == 80
|
1888
|
+
end
|
1889
|
+
|
1516
1890
|
it "should have a path of '/'" do
|
1517
1891
|
@uri.path.should == "/"
|
1518
1892
|
end
|
@@ -1578,6 +1952,17 @@ describe Addressable::URI, "when parsed from " +
|
|
1578
1952
|
it "should be identical to its duplicate" do
|
1579
1953
|
@uri.should == @uri.dup
|
1580
1954
|
end
|
1955
|
+
|
1956
|
+
it "should have an origin of 'http://example.com:8080'" do
|
1957
|
+
@uri.origin.should == 'http://example.com:8080'
|
1958
|
+
end
|
1959
|
+
|
1960
|
+
it "should not change if encoded with the normalizing algorithm" do
|
1961
|
+
Addressable::URI.normalized_encode(@uri).to_s.should ==
|
1962
|
+
"http://example.com:8080/"
|
1963
|
+
Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
|
1964
|
+
"http://example.com:8080/"
|
1965
|
+
end
|
1581
1966
|
end
|
1582
1967
|
|
1583
1968
|
describe Addressable::URI, "when parsed from " +
|
@@ -1597,47 +1982,210 @@ describe Addressable::URI, "when parsed from " +
|
|
1597
1982
|
it "should normalize to 'http://example.com/'" do
|
1598
1983
|
@uri.normalize.should === "http://example.com/"
|
1599
1984
|
end
|
1985
|
+
|
1986
|
+
it "should have an origin of 'http://example.com'" do
|
1987
|
+
@uri.origin.should == 'http://example.com'
|
1988
|
+
end
|
1600
1989
|
end
|
1601
1990
|
|
1602
1991
|
describe Addressable::URI, "when parsed from " +
|
1603
|
-
"'http://example.com
|
1992
|
+
"'http://example.com/..'" do
|
1604
1993
|
before do
|
1605
|
-
@uri = Addressable::URI.parse("http://example.com
|
1994
|
+
@uri = Addressable::URI.parse("http://example.com/..")
|
1606
1995
|
end
|
1607
1996
|
|
1608
|
-
it "should
|
1609
|
-
@uri.
|
1997
|
+
it "should have the correct port" do
|
1998
|
+
@uri.inferred_port.should == 80
|
1610
1999
|
end
|
1611
2000
|
|
1612
|
-
it "should
|
1613
|
-
@uri.
|
2001
|
+
it "should not be considered to be in normal form" do
|
2002
|
+
@uri.normalize.should_not be_eql(@uri)
|
1614
2003
|
end
|
1615
2004
|
|
1616
|
-
it "should
|
1617
|
-
@uri.
|
2005
|
+
it "should normalize to 'http://example.com/'" do
|
2006
|
+
@uri.normalize.should === "http://example.com/"
|
1618
2007
|
end
|
2008
|
+
end
|
1619
2009
|
|
1620
|
-
|
1621
|
-
|
2010
|
+
describe Addressable::URI, "when parsed from " +
|
2011
|
+
"'http://example.com/../..'" do
|
2012
|
+
before do
|
2013
|
+
@uri = Addressable::URI.parse("http://example.com/../..")
|
1622
2014
|
end
|
1623
2015
|
|
1624
|
-
it "should have
|
1625
|
-
@uri.
|
2016
|
+
it "should have the correct port" do
|
2017
|
+
@uri.inferred_port.should == 80
|
1626
2018
|
end
|
1627
2019
|
|
1628
|
-
it "should
|
1629
|
-
@uri.
|
2020
|
+
it "should not be considered to be in normal form" do
|
2021
|
+
@uri.normalize.should_not be_eql(@uri)
|
1630
2022
|
end
|
1631
2023
|
|
1632
|
-
it "should
|
1633
|
-
@uri.
|
2024
|
+
it "should normalize to 'http://example.com/'" do
|
2025
|
+
@uri.normalize.should === "http://example.com/"
|
1634
2026
|
end
|
2027
|
+
end
|
1635
2028
|
|
1636
|
-
|
1637
|
-
|
2029
|
+
describe Addressable::URI, "when parsed from " +
|
2030
|
+
"'http://example.com/path(/..'" do
|
2031
|
+
before do
|
2032
|
+
@uri = Addressable::URI.parse("http://example.com/path(/..")
|
1638
2033
|
end
|
1639
2034
|
|
1640
|
-
it "should have
|
2035
|
+
it "should have the correct port" do
|
2036
|
+
@uri.inferred_port.should == 80
|
2037
|
+
end
|
2038
|
+
|
2039
|
+
it "should not be considered to be in normal form" do
|
2040
|
+
@uri.normalize.should_not be_eql(@uri)
|
2041
|
+
end
|
2042
|
+
|
2043
|
+
it "should normalize to 'http://example.com/'" do
|
2044
|
+
@uri.normalize.should === "http://example.com/"
|
2045
|
+
end
|
2046
|
+
end
|
2047
|
+
|
2048
|
+
describe Addressable::URI, "when parsed from " +
|
2049
|
+
"'http://example.com/(path)/..'" do
|
2050
|
+
before do
|
2051
|
+
@uri = Addressable::URI.parse("http://example.com/(path)/..")
|
2052
|
+
end
|
2053
|
+
|
2054
|
+
it "should have the correct port" do
|
2055
|
+
@uri.inferred_port.should == 80
|
2056
|
+
end
|
2057
|
+
|
2058
|
+
it "should not be considered to be in normal form" do
|
2059
|
+
@uri.normalize.should_not be_eql(@uri)
|
2060
|
+
end
|
2061
|
+
|
2062
|
+
it "should normalize to 'http://example.com/'" do
|
2063
|
+
@uri.normalize.should === "http://example.com/"
|
2064
|
+
end
|
2065
|
+
end
|
2066
|
+
|
2067
|
+
describe Addressable::URI, "when parsed from " +
|
2068
|
+
"'http://example.com/path(/../'" do
|
2069
|
+
before do
|
2070
|
+
@uri = Addressable::URI.parse("http://example.com/path(/../")
|
2071
|
+
end
|
2072
|
+
|
2073
|
+
it "should have the correct port" do
|
2074
|
+
@uri.inferred_port.should == 80
|
2075
|
+
end
|
2076
|
+
|
2077
|
+
it "should not be considered to be in normal form" do
|
2078
|
+
@uri.normalize.should_not be_eql(@uri)
|
2079
|
+
end
|
2080
|
+
|
2081
|
+
it "should normalize to 'http://example.com/'" do
|
2082
|
+
@uri.normalize.should === "http://example.com/"
|
2083
|
+
end
|
2084
|
+
end
|
2085
|
+
|
2086
|
+
describe Addressable::URI, "when parsed from " +
|
2087
|
+
"'http://example.com/(path)/../'" do
|
2088
|
+
before do
|
2089
|
+
@uri = Addressable::URI.parse("http://example.com/(path)/../")
|
2090
|
+
end
|
2091
|
+
|
2092
|
+
it "should have the correct port" do
|
2093
|
+
@uri.inferred_port.should == 80
|
2094
|
+
end
|
2095
|
+
|
2096
|
+
it "should not be considered to be in normal form" do
|
2097
|
+
@uri.normalize.should_not be_eql(@uri)
|
2098
|
+
end
|
2099
|
+
|
2100
|
+
it "should normalize to 'http://example.com/'" do
|
2101
|
+
@uri.normalize.should === "http://example.com/"
|
2102
|
+
end
|
2103
|
+
end
|
2104
|
+
|
2105
|
+
describe Addressable::URI, "when parsed from '/a/b/c/./../../g'" do
|
2106
|
+
before do
|
2107
|
+
@uri = Addressable::URI.parse("/a/b/c/./../../g")
|
2108
|
+
end
|
2109
|
+
|
2110
|
+
it "should not be considered to be in normal form" do
|
2111
|
+
@uri.normalize.should_not be_eql(@uri)
|
2112
|
+
end
|
2113
|
+
|
2114
|
+
# Section 5.2.4 of RFC 3986
|
2115
|
+
it "should normalize to '/a/g'" do
|
2116
|
+
@uri.normalize.should === "/a/g"
|
2117
|
+
end
|
2118
|
+
end
|
2119
|
+
|
2120
|
+
describe Addressable::URI, "when parsed from 'mid/content=5/../6'" do
|
2121
|
+
before do
|
2122
|
+
@uri = Addressable::URI.parse("mid/content=5/../6")
|
2123
|
+
end
|
2124
|
+
|
2125
|
+
it "should not be considered to be in normal form" do
|
2126
|
+
@uri.normalize.should_not be_eql(@uri)
|
2127
|
+
end
|
2128
|
+
|
2129
|
+
# Section 5.2.4 of RFC 3986
|
2130
|
+
it "should normalize to 'mid/6'" do
|
2131
|
+
@uri.normalize.should === "mid/6"
|
2132
|
+
end
|
2133
|
+
end
|
2134
|
+
|
2135
|
+
describe Addressable::URI, "when parsed from " +
|
2136
|
+
"'http://www.example.com///../'" do
|
2137
|
+
before do
|
2138
|
+
@uri = Addressable::URI.parse('http://www.example.com///../')
|
2139
|
+
end
|
2140
|
+
|
2141
|
+
it "should not be considered to be in normal form" do
|
2142
|
+
@uri.normalize.should_not be_eql(@uri)
|
2143
|
+
end
|
2144
|
+
|
2145
|
+
it "should normalize to 'http://www.example.com//'" do
|
2146
|
+
@uri.normalize.should === "http://www.example.com//"
|
2147
|
+
end
|
2148
|
+
end
|
2149
|
+
|
2150
|
+
describe Addressable::URI, "when parsed from " +
|
2151
|
+
"'http://example.com/path/to/resource/'" do
|
2152
|
+
before do
|
2153
|
+
@uri = Addressable::URI.parse("http://example.com/path/to/resource/")
|
2154
|
+
end
|
2155
|
+
|
2156
|
+
it "should use the 'http' scheme" do
|
2157
|
+
@uri.scheme.should == "http"
|
2158
|
+
end
|
2159
|
+
|
2160
|
+
it "should have an authority segment of 'example.com'" do
|
2161
|
+
@uri.authority.should == "example.com"
|
2162
|
+
end
|
2163
|
+
|
2164
|
+
it "should have a host of 'example.com'" do
|
2165
|
+
@uri.host.should == "example.com"
|
2166
|
+
end
|
2167
|
+
|
2168
|
+
it "should have no username" do
|
2169
|
+
@uri.user.should == nil
|
2170
|
+
end
|
2171
|
+
|
2172
|
+
it "should have no password" do
|
2173
|
+
@uri.password.should == nil
|
2174
|
+
end
|
2175
|
+
|
2176
|
+
it "should use port 80" do
|
2177
|
+
@uri.inferred_port.should == 80
|
2178
|
+
end
|
2179
|
+
|
2180
|
+
it "should have a path of '/path/to/resource/'" do
|
2181
|
+
@uri.path.should == "/path/to/resource/"
|
2182
|
+
end
|
2183
|
+
|
2184
|
+
it "should have no query string" do
|
2185
|
+
@uri.query.should == nil
|
2186
|
+
end
|
2187
|
+
|
2188
|
+
it "should have no fragment" do
|
1641
2189
|
@uri.fragment.should == nil
|
1642
2190
|
end
|
1643
2191
|
|
@@ -2122,6 +2670,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2122
2670
|
it "should be considered to be in normal form" do
|
2123
2671
|
@uri.normalize.should be_eql(@uri)
|
2124
2672
|
end
|
2673
|
+
|
2674
|
+
it "should have a 'null' origin" do
|
2675
|
+
@uri.origin.should == 'null'
|
2676
|
+
end
|
2125
2677
|
end
|
2126
2678
|
|
2127
2679
|
describe Addressable::URI, "when parsed from " +
|
@@ -2163,6 +2715,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2163
2715
|
it "should be considered to be in normal form" do
|
2164
2716
|
@uri.normalize.should be_eql(@uri)
|
2165
2717
|
end
|
2718
|
+
|
2719
|
+
it "should have a 'null' origin" do
|
2720
|
+
@uri.origin.should == 'null'
|
2721
|
+
end
|
2166
2722
|
end
|
2167
2723
|
|
2168
2724
|
describe Addressable::URI, "when parsed from " +
|
@@ -2383,21 +2939,22 @@ describe Addressable::URI, "when parsed from " +
|
|
2383
2939
|
end
|
2384
2940
|
|
2385
2941
|
it "should have the correct query string after hash assignment" do
|
2386
|
-
@uri.query_values = {"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"}
|
2942
|
+
@uri.query_values = {"?uestion mark" => "=sign", "hello" => "g\xC3\xBCnther"}
|
2387
2943
|
@uri.query.split("&").should include("%3Fuestion%20mark=%3Dsign")
|
2388
2944
|
@uri.query.split("&").should include("hello=g%C3%BCnther")
|
2389
2945
|
@uri.query_values.should == {
|
2390
|
-
"?uestion mark"=>"=sign", "hello"=>"g\xC3\xBCnther"
|
2946
|
+
"?uestion mark" => "=sign", "hello" => "g\xC3\xBCnther"
|
2391
2947
|
}
|
2392
2948
|
end
|
2393
2949
|
|
2394
2950
|
it "should have the correct query string after flag hash assignment" do
|
2395
|
-
@uri.query_values = {'flag?1' =>
|
2951
|
+
@uri.query_values = {'flag?1' => nil, 'fl=ag2' => nil, 'flag3' => nil}
|
2396
2952
|
@uri.query.split("&").should include("flag%3F1")
|
2397
2953
|
@uri.query.split("&").should include("fl%3Dag2")
|
2398
2954
|
@uri.query.split("&").should include("flag3")
|
2399
|
-
@uri.query_values.should ==
|
2400
|
-
|
2955
|
+
@uri.query_values(Array).sort.should == [["fl=ag2"], ["flag3"], ["flag?1"]]
|
2956
|
+
@uri.query_values(Hash).should == {
|
2957
|
+
'flag?1' => nil, 'fl=ag2' => nil, 'flag3' => nil
|
2401
2958
|
}
|
2402
2959
|
end
|
2403
2960
|
|
@@ -2503,6 +3060,76 @@ describe Addressable::URI, "when parsed from " +
|
|
2503
3060
|
it "should be identical to its duplicate" do
|
2504
3061
|
@uri.should == @uri.dup
|
2505
3062
|
end
|
3063
|
+
|
3064
|
+
it "should have an origin of 'http://example.com'" do
|
3065
|
+
@uri.origin.should == 'http://example.com'
|
3066
|
+
end
|
3067
|
+
end
|
3068
|
+
|
3069
|
+
describe Addressable::URI, "when parsed from " +
|
3070
|
+
"'http://example.com/search?q=Q%26A'" do
|
3071
|
+
|
3072
|
+
before do
|
3073
|
+
@uri = Addressable::URI.parse("http://example.com/search?q=Q%26A")
|
3074
|
+
end
|
3075
|
+
|
3076
|
+
it "should have a query of 'q=Q%26A'" do
|
3077
|
+
@uri.query.should == "q=Q%26A"
|
3078
|
+
end
|
3079
|
+
|
3080
|
+
it "should have query_values of {'q' => 'Q&A'}" do
|
3081
|
+
@uri.query_values.should == { 'q' => 'Q&A' }
|
3082
|
+
end
|
3083
|
+
|
3084
|
+
it "should normalize to the original uri " +
|
3085
|
+
"(with the ampersand properly percent-encoded)" do
|
3086
|
+
@uri.normalize.to_s.should == "http://example.com/search?q=Q%26A"
|
3087
|
+
end
|
3088
|
+
end
|
3089
|
+
|
3090
|
+
describe Addressable::URI, "when parsed from " +
|
3091
|
+
"'http://example.com/?&x=b'" do
|
3092
|
+
before do
|
3093
|
+
@uri = Addressable::URI.parse("http://example.com/?&x=b")
|
3094
|
+
end
|
3095
|
+
|
3096
|
+
it "should have a query of '&x=b'" do
|
3097
|
+
@uri.query.should == "&x=b"
|
3098
|
+
end
|
3099
|
+
|
3100
|
+
it "should have query_values of {'x' => 'b'}" do
|
3101
|
+
@uri.query_values.should == {'x' => 'b'}
|
3102
|
+
end
|
3103
|
+
end
|
3104
|
+
|
3105
|
+
describe Addressable::URI, "when parsed from " +
|
3106
|
+
"'http://example.com/?&&x=b'" do
|
3107
|
+
before do
|
3108
|
+
@uri = Addressable::URI.parse("http://example.com/?&&x=b")
|
3109
|
+
end
|
3110
|
+
|
3111
|
+
it "should have a query of '&&x=b'" do
|
3112
|
+
@uri.query.should == "&&x=b"
|
3113
|
+
end
|
3114
|
+
|
3115
|
+
it "should have query_values of {'x' => 'b'}" do
|
3116
|
+
@uri.query_values.should == {'x' => 'b'}
|
3117
|
+
end
|
3118
|
+
end
|
3119
|
+
|
3120
|
+
describe Addressable::URI, "when parsed from " +
|
3121
|
+
"'http://example.com/?q=a&&x=b'" do
|
3122
|
+
before do
|
3123
|
+
@uri = Addressable::URI.parse("http://example.com/?q=a&&x=b")
|
3124
|
+
end
|
3125
|
+
|
3126
|
+
it "should have a query of 'q=a&&x=b'" do
|
3127
|
+
@uri.query.should == "q=a&&x=b"
|
3128
|
+
end
|
3129
|
+
|
3130
|
+
it "should have query_values of {'q' => 'a, 'x' => 'b'}" do
|
3131
|
+
@uri.query_values.should == {'q' => 'a', 'x' => 'b'}
|
3132
|
+
end
|
2506
3133
|
end
|
2507
3134
|
|
2508
3135
|
describe Addressable::URI, "when parsed from " +
|
@@ -2516,7 +3143,7 @@ describe Addressable::URI, "when parsed from " +
|
|
2516
3143
|
end
|
2517
3144
|
|
2518
3145
|
it "should have query_values of {'q' => true, 'x' => 'b'}" do
|
2519
|
-
@uri.query_values.should == {'q' =>
|
3146
|
+
@uri.query_values.should == {'q' => nil, 'x' => 'b'}
|
2520
3147
|
end
|
2521
3148
|
end
|
2522
3149
|
|
@@ -2533,6 +3160,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2533
3160
|
it "should have query_values of {'q' => 'a b'}" do
|
2534
3161
|
@uri.query_values.should == {'q' => 'a b'}
|
2535
3162
|
end
|
3163
|
+
|
3164
|
+
it "should have a normalized query of 'q=a+b'" do
|
3165
|
+
@uri.normalized_query.should == "q=a+b"
|
3166
|
+
end
|
2536
3167
|
end
|
2537
3168
|
|
2538
3169
|
describe Addressable::URI, "when parsed from " +
|
@@ -2548,6 +3179,43 @@ describe Addressable::URI, "when parsed from " +
|
|
2548
3179
|
it "should have query_values of {'q' => 'a+b'}" do
|
2549
3180
|
@uri.query_values.should == {'q' => 'a+b'}
|
2550
3181
|
end
|
3182
|
+
|
3183
|
+
it "should have a normalized query of 'q=a%2Bb'" do
|
3184
|
+
@uri.normalized_query.should == "q=a%2Bb"
|
3185
|
+
end
|
3186
|
+
end
|
3187
|
+
|
3188
|
+
describe Addressable::URI, "when parsed from " +
|
3189
|
+
"'http://example.com/?v=%7E&w=%&x=%25&y=%2B&z=C%CC%A7'" do
|
3190
|
+
before do
|
3191
|
+
@uri = Addressable::URI.parse("http://example.com/?v=%7E&w=%&x=%25&y=%2B&z=C%CC%A7")
|
3192
|
+
end
|
3193
|
+
|
3194
|
+
it "should have a normalized query of 'v=~&w=%25&x=%25&y=%2B&z=%C3%87'" do
|
3195
|
+
@uri.normalized_query.should == "v=~&w=%25&x=%25&y=%2B&z=%C3%87"
|
3196
|
+
end
|
3197
|
+
end
|
3198
|
+
|
3199
|
+
describe Addressable::URI, "when parsed from " +
|
3200
|
+
"'http://example.com/?v=%7E&w=%&x=%25&y=+&z=C%CC%A7'" do
|
3201
|
+
before do
|
3202
|
+
@uri = Addressable::URI.parse("http://example.com/?v=%7E&w=%&x=%25&y=+&z=C%CC%A7")
|
3203
|
+
end
|
3204
|
+
|
3205
|
+
it "should have a normalized query of 'v=~&w=%25&x=%25&y=+&z=%C3%87'" do
|
3206
|
+
@uri.normalized_query.should == "v=~&w=%25&x=%25&y=+&z=%C3%87"
|
3207
|
+
end
|
3208
|
+
end
|
3209
|
+
|
3210
|
+
describe Addressable::URI, "when parsed from " +
|
3211
|
+
"'http://example.com/sound%2bvision'" do
|
3212
|
+
before do
|
3213
|
+
@uri = Addressable::URI.parse("http://example.com/sound%2bvision")
|
3214
|
+
end
|
3215
|
+
|
3216
|
+
it "should have a normalized path of '/sound+vision'" do
|
3217
|
+
@uri.normalized_path.should == '/sound+vision'
|
3218
|
+
end
|
2551
3219
|
end
|
2552
3220
|
|
2553
3221
|
describe Addressable::URI, "when parsed from " +
|
@@ -2595,6 +3263,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2595
3263
|
@uri.host.should == "example.com"
|
2596
3264
|
end
|
2597
3265
|
|
3266
|
+
it "should have default_port 80" do
|
3267
|
+
@uri.default_port.should == 80
|
3268
|
+
end
|
3269
|
+
|
2598
3270
|
it "should use port 80" do
|
2599
3271
|
@uri.inferred_port.should == 80
|
2600
3272
|
end
|
@@ -2885,6 +3557,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2885
3557
|
@uri.route_from("http://example.com/")
|
2886
3558
|
end).should raise_error(ArgumentError, /\/\/example.com\//)
|
2887
3559
|
end
|
3560
|
+
|
3561
|
+
it "should have a 'null' origin" do
|
3562
|
+
@uri.origin.should == 'null'
|
3563
|
+
end
|
2888
3564
|
end
|
2889
3565
|
|
2890
3566
|
describe Addressable::URI, "when parsed from " +
|
@@ -2916,6 +3592,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2916
3592
|
@uri.normalize.to_s.should == "http://example.com/"
|
2917
3593
|
@uri.normalize!.to_s.should == "http://example.com/"
|
2918
3594
|
end
|
3595
|
+
|
3596
|
+
it "should have a 'null' origin" do
|
3597
|
+
@uri.origin.should == 'null'
|
3598
|
+
end
|
2919
3599
|
end
|
2920
3600
|
|
2921
3601
|
describe Addressable::URI, "when parsed from " +
|
@@ -2929,6 +3609,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2929
3609
|
@uri.should ==
|
2930
3610
|
Addressable::URI.parse("eXAMPLE://a/./b/../b/%63/%7bfoo%7d")
|
2931
3611
|
end
|
3612
|
+
|
3613
|
+
it "should have an origin of 'example://a'" do
|
3614
|
+
@uri.origin.should == 'example://a'
|
3615
|
+
end
|
2932
3616
|
end
|
2933
3617
|
|
2934
3618
|
describe Addressable::URI, "when parsed from " +
|
@@ -2983,6 +3667,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2983
3667
|
it "should have no scheme" do
|
2984
3668
|
@uri.scheme.should == nil
|
2985
3669
|
end
|
3670
|
+
|
3671
|
+
it "should have a 'null' origin" do
|
3672
|
+
@uri.origin.should == 'null'
|
3673
|
+
end
|
2986
3674
|
end
|
2987
3675
|
|
2988
3676
|
describe Addressable::URI, "when parsed from " +
|
@@ -2998,6 +3686,10 @@ describe Addressable::URI, "when parsed from " +
|
|
2998
3686
|
it "should have a scheme of 'this'" do
|
2999
3687
|
@uri.scheme.should == "this"
|
3000
3688
|
end
|
3689
|
+
|
3690
|
+
it "should have a 'null' origin" do
|
3691
|
+
@uri.origin.should == 'null'
|
3692
|
+
end
|
3001
3693
|
end
|
3002
3694
|
|
3003
3695
|
describe Addressable::URI, "when parsed from '?'" do
|
@@ -3005,17 +3697,14 @@ describe Addressable::URI, "when parsed from '?'" do
|
|
3005
3697
|
@uri = Addressable::URI.parse("?")
|
3006
3698
|
end
|
3007
3699
|
|
3008
|
-
it "should have the correct
|
3700
|
+
it "should have the correct return type" do
|
3009
3701
|
@uri.query_values.should == {}
|
3010
|
-
@uri.query_values(
|
3702
|
+
@uri.query_values(Hash).should == {}
|
3703
|
+
@uri.query_values(Array).should == []
|
3011
3704
|
end
|
3012
3705
|
|
3013
|
-
it "should have
|
3014
|
-
@uri.
|
3015
|
-
end
|
3016
|
-
|
3017
|
-
it "should have the correct flat notation query values" do
|
3018
|
-
@uri.query_values(:notation => :flat).should == {}
|
3706
|
+
it "should have a 'null' origin" do
|
3707
|
+
@uri.origin.should == 'null'
|
3019
3708
|
end
|
3020
3709
|
end
|
3021
3710
|
|
@@ -3028,11 +3717,37 @@ describe Addressable::URI, "when parsed from '?one=1&two=2&three=3'" do
|
|
3028
3717
|
@uri.query_values.should == {"one" => "1", "two" => "2", "three" => "3"}
|
3029
3718
|
end
|
3030
3719
|
|
3031
|
-
it "should raise an error for invalid
|
3720
|
+
it "should raise an error for invalid return type values" do
|
3032
3721
|
(lambda do
|
3033
|
-
@uri.query_values(
|
3722
|
+
@uri.query_values(Fixnum)
|
3034
3723
|
end).should raise_error(ArgumentError)
|
3035
3724
|
end
|
3725
|
+
|
3726
|
+
it "should have the correct array query values" do
|
3727
|
+
@uri.query_values(Array).should == [
|
3728
|
+
["one", "1"], ["two", "2"], ["three", "3"]
|
3729
|
+
]
|
3730
|
+
end
|
3731
|
+
|
3732
|
+
it "should have a 'null' origin" do
|
3733
|
+
@uri.origin.should == 'null'
|
3734
|
+
end
|
3735
|
+
end
|
3736
|
+
|
3737
|
+
describe Addressable::URI, "when parsed from '?one=1=uno&two=2=dos'" do
|
3738
|
+
before do
|
3739
|
+
@uri = Addressable::URI.parse("?one=1=uno&two=2=dos")
|
3740
|
+
end
|
3741
|
+
|
3742
|
+
it "should have the correct query values" do
|
3743
|
+
@uri.query_values.should == {"one" => "1=uno", "two" => "2=dos"}
|
3744
|
+
end
|
3745
|
+
|
3746
|
+
it "should have the correct array query values" do
|
3747
|
+
@uri.query_values(Array).should == [
|
3748
|
+
["one", "1=uno"], ["two", "2=dos"]
|
3749
|
+
]
|
3750
|
+
end
|
3036
3751
|
end
|
3037
3752
|
|
3038
3753
|
describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
|
@@ -3041,13 +3756,13 @@ describe Addressable::URI, "when parsed from '?one[two][three]=four'" do
|
|
3041
3756
|
end
|
3042
3757
|
|
3043
3758
|
it "should have the correct query values" do
|
3044
|
-
@uri.query_values.should == {"one
|
3759
|
+
@uri.query_values.should == {"one[two][three]" => "four"}
|
3045
3760
|
end
|
3046
3761
|
|
3047
|
-
it "should have the correct
|
3048
|
-
@uri.query_values(
|
3049
|
-
"one[two][three]"
|
3050
|
-
|
3762
|
+
it "should have the correct array query values" do
|
3763
|
+
@uri.query_values(Array).should == [
|
3764
|
+
["one[two][three]", "four"]
|
3765
|
+
]
|
3051
3766
|
end
|
3052
3767
|
end
|
3053
3768
|
|
@@ -3056,16 +3771,16 @@ describe Addressable::URI, "when parsed from '?one.two.three=four'" do
|
|
3056
3771
|
@uri = Addressable::URI.parse("?one.two.three=four")
|
3057
3772
|
end
|
3058
3773
|
|
3059
|
-
it "should have the correct
|
3060
|
-
@uri.query_values
|
3061
|
-
"one
|
3774
|
+
it "should have the correct query values" do
|
3775
|
+
@uri.query_values.should == {
|
3776
|
+
"one.two.three" => "four"
|
3062
3777
|
}
|
3063
3778
|
end
|
3064
3779
|
|
3065
|
-
it "should have the correct
|
3066
|
-
@uri.query_values(
|
3067
|
-
"one.two.three"
|
3068
|
-
|
3780
|
+
it "should have the correct array query values" do
|
3781
|
+
@uri.query_values(Array).should == [
|
3782
|
+
["one.two.three", "four"]
|
3783
|
+
]
|
3069
3784
|
end
|
3070
3785
|
end
|
3071
3786
|
|
@@ -3075,17 +3790,16 @@ describe Addressable::URI, "when parsed from " +
|
|
3075
3790
|
@uri = Addressable::URI.parse("?one[two][three]=four&one[two][five]=six")
|
3076
3791
|
end
|
3077
3792
|
|
3078
|
-
it "should have the correct
|
3079
|
-
@uri.query_values
|
3080
|
-
"one
|
3793
|
+
it "should have the correct query values" do
|
3794
|
+
@uri.query_values.should == {
|
3795
|
+
"one[two][three]" => "four", "one[two][five]" => "six"
|
3081
3796
|
}
|
3082
3797
|
end
|
3083
3798
|
|
3084
|
-
it "should have the correct
|
3085
|
-
@uri.query_values(
|
3086
|
-
"one[two][three]"
|
3087
|
-
|
3088
|
-
}
|
3799
|
+
it "should have the correct array query values" do
|
3800
|
+
@uri.query_values(Array).should == [
|
3801
|
+
["one[two][three]", "four"], ["one[two][five]", "six"]
|
3802
|
+
]
|
3089
3803
|
end
|
3090
3804
|
end
|
3091
3805
|
|
@@ -3095,17 +3809,37 @@ describe Addressable::URI, "when parsed from " +
|
|
3095
3809
|
@uri = Addressable::URI.parse("?one.two.three=four&one.two.five=six")
|
3096
3810
|
end
|
3097
3811
|
|
3098
|
-
it "should have the correct
|
3099
|
-
@uri.query_values
|
3100
|
-
"one
|
3812
|
+
it "should have the correct query values" do
|
3813
|
+
@uri.query_values.should == {
|
3814
|
+
"one.two.three" => "four", "one.two.five" => "six"
|
3101
3815
|
}
|
3102
3816
|
end
|
3103
3817
|
|
3104
|
-
it "should have the correct
|
3105
|
-
@uri.query_values(
|
3106
|
-
"one.two.three"
|
3107
|
-
|
3108
|
-
|
3818
|
+
it "should have the correct array query values" do
|
3819
|
+
@uri.query_values(Array).should == [
|
3820
|
+
["one.two.three", "four"], ["one.two.five", "six"]
|
3821
|
+
]
|
3822
|
+
end
|
3823
|
+
end
|
3824
|
+
|
3825
|
+
describe Addressable::URI, "when parsed from " +
|
3826
|
+
"'?one=two&one=three'" do
|
3827
|
+
before do
|
3828
|
+
@uri = Addressable::URI.parse(
|
3829
|
+
"?one=two&one=three&one=four"
|
3830
|
+
)
|
3831
|
+
end
|
3832
|
+
|
3833
|
+
it "should have correct array query values" do
|
3834
|
+
@uri.query_values(Array).should ==
|
3835
|
+
[['one', 'two'], ['one', 'three'], ['one', 'four']]
|
3836
|
+
end
|
3837
|
+
|
3838
|
+
it "should have correct hash query values" do
|
3839
|
+
pending("This is probably more desirable behavior.") do
|
3840
|
+
@uri.query_values(Hash).should ==
|
3841
|
+
{'one' => ['two', 'three', 'four']}
|
3842
|
+
end
|
3109
3843
|
end
|
3110
3844
|
end
|
3111
3845
|
|
@@ -3117,16 +3851,14 @@ describe Addressable::URI, "when parsed from " +
|
|
3117
3851
|
)
|
3118
3852
|
end
|
3119
3853
|
|
3120
|
-
it "should have
|
3121
|
-
@uri.query_values(
|
3122
|
-
"one" => {"two" => {"three" => ["four", "five"]}}
|
3123
|
-
}
|
3854
|
+
it "should have correct query values" do
|
3855
|
+
@uri.query_values(Hash).should == {"one[two][three][]" => "five"}
|
3124
3856
|
end
|
3125
3857
|
|
3126
|
-
it "should
|
3127
|
-
(
|
3128
|
-
|
3129
|
-
|
3858
|
+
it "should have correct array query values" do
|
3859
|
+
@uri.query_values(Array).should == [
|
3860
|
+
["one[two][three][]", "four"], ["one[two][three][]", "five"]
|
3861
|
+
]
|
3130
3862
|
end
|
3131
3863
|
end
|
3132
3864
|
|
@@ -3138,9 +3870,39 @@ describe Addressable::URI, "when parsed from " +
|
|
3138
3870
|
)
|
3139
3871
|
end
|
3140
3872
|
|
3141
|
-
it "should have the correct
|
3142
|
-
@uri.query_values
|
3143
|
-
"one" =>
|
3873
|
+
it "should have the correct query values" do
|
3874
|
+
@uri.query_values.should == {
|
3875
|
+
"one[two][three][0]" => "four", "one[two][three][1]" => "five"
|
3876
|
+
}
|
3877
|
+
end
|
3878
|
+
end
|
3879
|
+
|
3880
|
+
describe Addressable::URI, "when parsed from " +
|
3881
|
+
"'?one[two][three][1]=four&one[two][three][0]=five'" do
|
3882
|
+
before do
|
3883
|
+
@uri = Addressable::URI.parse(
|
3884
|
+
"?one[two][three][1]=four&one[two][three][0]=five"
|
3885
|
+
)
|
3886
|
+
end
|
3887
|
+
|
3888
|
+
it "should have the correct query values" do
|
3889
|
+
@uri.query_values.should == {
|
3890
|
+
"one[two][three][1]" => "four", "one[two][three][0]" => "five"
|
3891
|
+
}
|
3892
|
+
end
|
3893
|
+
end
|
3894
|
+
|
3895
|
+
describe Addressable::URI, "when parsed from " +
|
3896
|
+
"'?one[two][three][2]=four&one[two][three][1]=five'" do
|
3897
|
+
before do
|
3898
|
+
@uri = Addressable::URI.parse(
|
3899
|
+
"?one[two][three][2]=four&one[two][three][1]=five"
|
3900
|
+
)
|
3901
|
+
end
|
3902
|
+
|
3903
|
+
it "should have the correct query values" do
|
3904
|
+
@uri.query_values.should == {
|
3905
|
+
"one[two][three][2]" => "four", "one[two][three][1]" => "five"
|
3144
3906
|
}
|
3145
3907
|
end
|
3146
3908
|
end
|
@@ -3160,6 +3922,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3160
3922
|
Addressable::URI.normalized_encode(@uri.to_s).should ==
|
3161
3923
|
"http://www.詹姆斯.com/"
|
3162
3924
|
end
|
3925
|
+
|
3926
|
+
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
|
3927
|
+
@uri.origin.should == 'http://www.xn--8ws00zhy3a.com'
|
3928
|
+
end
|
3163
3929
|
end
|
3164
3930
|
|
3165
3931
|
describe Addressable::URI, "when parsed from " +
|
@@ -3179,6 +3945,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3179
3945
|
Addressable::URI.normalized_encode(@uri.to_s).should ==
|
3180
3946
|
"http://www.詹姆斯.com/%20some%20spaces%20/"
|
3181
3947
|
end
|
3948
|
+
|
3949
|
+
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
|
3950
|
+
@uri.origin.should == 'http://www.xn--8ws00zhy3a.com'
|
3951
|
+
end
|
3182
3952
|
end
|
3183
3953
|
|
3184
3954
|
describe Addressable::URI, "when parsed from " +
|
@@ -3198,6 +3968,10 @@ describe Addressable::URI, "when parsed from " +
|
|
3198
3968
|
display_string.encoding.to_s.should == Encoding::UTF_8.to_s
|
3199
3969
|
end
|
3200
3970
|
end
|
3971
|
+
|
3972
|
+
it "should have an origin of 'http://www.xn--8ws00zhy3a.com'" do
|
3973
|
+
@uri.origin.should == 'http://www.xn--8ws00zhy3a.com'
|
3974
|
+
end
|
3201
3975
|
end
|
3202
3976
|
|
3203
3977
|
describe Addressable::URI, "when parsed from " +
|
@@ -3235,6 +4009,13 @@ describe Addressable::URI, "when parsed from a percent-encoded IRI" do
|
|
3235
4009
|
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
|
3236
4010
|
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp/"
|
3237
4011
|
end
|
4012
|
+
|
4013
|
+
it "should have the correct origin" do
|
4014
|
+
@uri.origin.should == (
|
4015
|
+
"http://www.xn--n8jaaaaai5bhf7as8fsfk3jnknefdde3f" +
|
4016
|
+
"g11amb5gzdb4wi9bya3kc6lra.w3.mag.keio.ac.jp"
|
4017
|
+
)
|
4018
|
+
end
|
3238
4019
|
end
|
3239
4020
|
|
3240
4021
|
describe Addressable::URI, "with a base uri of 'http://a/b/c/d;p?q'" do
|
@@ -3567,6 +4348,11 @@ describe Addressable::URI, "when given a UNIX root directory" do
|
|
3567
4348
|
@uri = Addressable::URI.convert_path(@path)
|
3568
4349
|
@uri.to_str.should == "file:///"
|
3569
4350
|
end
|
4351
|
+
|
4352
|
+
it "should have an origin of 'file://'" do
|
4353
|
+
@uri = Addressable::URI.convert_path(@path)
|
4354
|
+
@uri.origin.should == 'file://'
|
4355
|
+
end
|
3570
4356
|
end
|
3571
4357
|
|
3572
4358
|
describe Addressable::URI, "when given a Windows root directory" do
|
@@ -3578,17 +4364,27 @@ describe Addressable::URI, "when given a Windows root directory" do
|
|
3578
4364
|
@uri = Addressable::URI.convert_path(@path)
|
3579
4365
|
@uri.to_str.should == "file:///c:/"
|
3580
4366
|
end
|
4367
|
+
|
4368
|
+
it "should have an origin of 'file://'" do
|
4369
|
+
@uri = Addressable::URI.convert_path(@path)
|
4370
|
+
@uri.origin.should == 'file://'
|
4371
|
+
end
|
3581
4372
|
end
|
3582
4373
|
|
3583
|
-
describe Addressable::URI, "when given the path '/
|
4374
|
+
describe Addressable::URI, "when given the path '/one/two/'" do
|
3584
4375
|
before do
|
3585
|
-
@path = '/
|
4376
|
+
@path = '/one/two/'
|
3586
4377
|
end
|
3587
4378
|
|
3588
4379
|
it "should convert to " +
|
3589
|
-
"\'file:///
|
4380
|
+
"\'file:///one/two/\'" do
|
3590
4381
|
@uri = Addressable::URI.convert_path(@path)
|
3591
|
-
@uri.to_str.should == "file:///
|
4382
|
+
@uri.to_str.should == "file:///one/two/"
|
4383
|
+
end
|
4384
|
+
|
4385
|
+
it "should have an origin of 'file://'" do
|
4386
|
+
@uri = Addressable::URI.convert_path(@path)
|
4387
|
+
@uri.origin.should == 'file://'
|
3592
4388
|
end
|
3593
4389
|
end
|
3594
4390
|
|
@@ -3603,6 +4399,11 @@ describe Addressable::URI, "when given the path " +
|
|
3603
4399
|
@uri = Addressable::URI.convert_path(@path)
|
3604
4400
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3605
4401
|
end
|
4402
|
+
|
4403
|
+
it "should have an origin of 'file://'" do
|
4404
|
+
@uri = Addressable::URI.convert_path(@path)
|
4405
|
+
@uri.origin.should == 'file://'
|
4406
|
+
end
|
3606
4407
|
end
|
3607
4408
|
|
3608
4409
|
describe Addressable::URI, "when given the path " +
|
@@ -3616,6 +4417,11 @@ describe Addressable::URI, "when given the path " +
|
|
3616
4417
|
@uri = Addressable::URI.convert_path(@path)
|
3617
4418
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3618
4419
|
end
|
4420
|
+
|
4421
|
+
it "should have an origin of 'file://'" do
|
4422
|
+
@uri = Addressable::URI.convert_path(@path)
|
4423
|
+
@uri.origin.should == 'file://'
|
4424
|
+
end
|
3619
4425
|
end
|
3620
4426
|
|
3621
4427
|
describe Addressable::URI, "when given the path " +
|
@@ -3629,6 +4435,11 @@ describe Addressable::URI, "when given the path " +
|
|
3629
4435
|
@uri = Addressable::URI.convert_path(@path)
|
3630
4436
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3631
4437
|
end
|
4438
|
+
|
4439
|
+
it "should have an origin of 'file://'" do
|
4440
|
+
@uri = Addressable::URI.convert_path(@path)
|
4441
|
+
@uri.origin.should == 'file://'
|
4442
|
+
end
|
3632
4443
|
end
|
3633
4444
|
|
3634
4445
|
describe Addressable::URI, "when given the path " +
|
@@ -3642,6 +4453,11 @@ describe Addressable::URI, "when given the path " +
|
|
3642
4453
|
@uri = Addressable::URI.convert_path(@path)
|
3643
4454
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3644
4455
|
end
|
4456
|
+
|
4457
|
+
it "should have an origin of 'file://'" do
|
4458
|
+
@uri = Addressable::URI.convert_path(@path)
|
4459
|
+
@uri.origin.should == 'file://'
|
4460
|
+
end
|
3645
4461
|
end
|
3646
4462
|
|
3647
4463
|
describe Addressable::URI, "when given the path " +
|
@@ -3655,6 +4471,11 @@ describe Addressable::URI, "when given the path " +
|
|
3655
4471
|
@uri = Addressable::URI.convert_path(@path)
|
3656
4472
|
@uri.to_str.should == "file:///c:/windows/My%20Documents%20100%20/foo.txt"
|
3657
4473
|
end
|
4474
|
+
|
4475
|
+
it "should have an origin of 'file://'" do
|
4476
|
+
@uri = Addressable::URI.convert_path(@path)
|
4477
|
+
@uri.origin.should == 'file://'
|
4478
|
+
end
|
3658
4479
|
end
|
3659
4480
|
|
3660
4481
|
describe Addressable::URI, "when given an http protocol URI" do
|
@@ -3703,7 +4524,7 @@ end
|
|
3703
4524
|
describe Addressable::URI, "when form encoding a hash" do
|
3704
4525
|
it "should result in correct percent encoded sequence" do
|
3705
4526
|
Addressable::URI.form_encode(
|
3706
|
-
|
4527
|
+
[["&one", "/1"], ["=two", "?2"], [":three", "#3"]]
|
3707
4528
|
).should == "%26one=%2F1&%3Dtwo=%3F2&%3Athree=%233"
|
3708
4529
|
end
|
3709
4530
|
|
@@ -3719,6 +4540,12 @@ describe Addressable::URI, "when form encoding a hash" do
|
|
3719
4540
|
).should == "key="
|
3720
4541
|
end
|
3721
4542
|
|
4543
|
+
it "should result in correct percent encoded sequence" do
|
4544
|
+
Addressable::URI.form_encode(
|
4545
|
+
{"q" => ["one", "two", "three"]}
|
4546
|
+
).should == "q=one&q=two&q=three"
|
4547
|
+
end
|
4548
|
+
|
3722
4549
|
it "should result in correctly encoded newlines" do
|
3723
4550
|
Addressable::URI.form_encode(
|
3724
4551
|
{"text" => "one\ntwo\rthree\r\nfour\n\r"}
|
@@ -3854,6 +4681,19 @@ describe Addressable::URI, "when normalizing a multibyte string" do
|
|
3854
4681
|
end
|
3855
4682
|
end
|
3856
4683
|
|
4684
|
+
describe Addressable::URI, "when normalizing a string but leaving some characters encoded" do
|
4685
|
+
it "should result in correct percent encoded sequence" do
|
4686
|
+
Addressable::URI.normalize_component("%58X%59Y%5AZ", "0-9a-zXY", "Y").should ==
|
4687
|
+
"XX%59Y%5A%5A"
|
4688
|
+
end
|
4689
|
+
end
|
4690
|
+
|
4691
|
+
describe Addressable::URI, "when encoding a string with existing encodings to upcase" do
|
4692
|
+
it "should result in correct percent encoded sequence" do
|
4693
|
+
Addressable::URI.encode_component("JK%4c", "0-9A-IKM-Za-z%", "L").should == "%4AK%4C"
|
4694
|
+
end
|
4695
|
+
end
|
4696
|
+
|
3857
4697
|
describe Addressable::URI, "when encoding a multibyte string" do
|
3858
4698
|
it "should result in correct percent encoded sequence" do
|
3859
4699
|
Addressable::URI.encode_component("günther").should == "g%C3%BCnther"
|
@@ -3899,6 +4739,20 @@ describe Addressable::URI, "when unencoding a multibyte string" do
|
|
3899
4739
|
end
|
3900
4740
|
end
|
3901
4741
|
|
4742
|
+
describe Addressable::URI, "when partially unencoding a string" do
|
4743
|
+
it "should unencode all characters by default" do
|
4744
|
+
Addressable::URI.unencode('%%25~%7e+%2b', String).should == '%%~~++'
|
4745
|
+
end
|
4746
|
+
|
4747
|
+
it "should unencode characters not in leave_encoded" do
|
4748
|
+
Addressable::URI.unencode('%%25~%7e+%2b', String, '~').should == '%%~%7e++'
|
4749
|
+
end
|
4750
|
+
|
4751
|
+
it "should leave characters in leave_encoded alone" do
|
4752
|
+
Addressable::URI.unencode('%%25~%7e+%2b', String, '%~+').should == '%%25~%7e+%2b'
|
4753
|
+
end
|
4754
|
+
end
|
4755
|
+
|
3902
4756
|
describe Addressable::URI, "when unencoding a bogus object" do
|
3903
4757
|
it "should raise a TypeError" do
|
3904
4758
|
(lambda do
|
@@ -3916,25 +4770,25 @@ end
|
|
3916
4770
|
describe Addressable::URI, "when encoding a bogus object" do
|
3917
4771
|
it "should raise a TypeError" do
|
3918
4772
|
(lambda do
|
3919
|
-
Addressable::URI.encode(
|
4773
|
+
Addressable::URI.encode(Object.new)
|
3920
4774
|
end).should raise_error(TypeError)
|
3921
4775
|
end
|
3922
4776
|
|
3923
4777
|
it "should raise a TypeError" do
|
3924
4778
|
(lambda do
|
3925
|
-
Addressable::URI.normalized_encode(
|
4779
|
+
Addressable::URI.normalized_encode(Object.new)
|
3926
4780
|
end).should raise_error(TypeError)
|
3927
4781
|
end
|
3928
4782
|
|
3929
4783
|
it "should raise a TypeError" do
|
3930
4784
|
(lambda do
|
3931
|
-
Addressable::URI.encode_component("günther",
|
4785
|
+
Addressable::URI.encode_component("günther", Object.new)
|
3932
4786
|
end).should raise_error(TypeError)
|
3933
4787
|
end
|
3934
4788
|
|
3935
4789
|
it "should raise a TypeError" do
|
3936
4790
|
(lambda do
|
3937
|
-
Addressable::URI.encode_component(
|
4791
|
+
Addressable::URI.encode_component(Object.new)
|
3938
4792
|
end).should raise_error(TypeError)
|
3939
4793
|
end
|
3940
4794
|
end
|
@@ -3949,8 +4803,25 @@ describe Addressable::URI, "when given the input " +
|
|
3949
4803
|
@uri = Addressable::URI.heuristic_parse(@input)
|
3950
4804
|
@uri.to_s.should == "http://example.com/"
|
3951
4805
|
end
|
4806
|
+
|
4807
|
+
it "should not raise error when frozen" do
|
4808
|
+
(lambda do
|
4809
|
+
Addressable::URI.heuristic_parse(@input).freeze.to_s
|
4810
|
+
end).should_not raise_error
|
4811
|
+
end
|
3952
4812
|
end
|
3953
4813
|
|
4814
|
+
describe Addressable::URI, "when given the input " +
|
4815
|
+
"'https://example.com/'" do
|
4816
|
+
before do
|
4817
|
+
@input = "https://example.com/"
|
4818
|
+
end
|
4819
|
+
|
4820
|
+
it "should heuristically parse to 'https://example.com/'" do
|
4821
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4822
|
+
@uri.to_s.should == "https://example.com/"
|
4823
|
+
end
|
4824
|
+
end
|
3954
4825
|
|
3955
4826
|
describe Addressable::URI, "when given the input " +
|
3956
4827
|
"'http:example.com/'" do
|
@@ -3970,6 +4841,24 @@ describe Addressable::URI, "when given the input " +
|
|
3970
4841
|
end
|
3971
4842
|
end
|
3972
4843
|
|
4844
|
+
describe Addressable::URI, "when given the input " +
|
4845
|
+
"'https:example.com/'" do
|
4846
|
+
before do
|
4847
|
+
@input = "https:example.com/"
|
4848
|
+
end
|
4849
|
+
|
4850
|
+
it "should heuristically parse to 'https://example.com/'" do
|
4851
|
+
@uri = Addressable::URI.heuristic_parse(@input)
|
4852
|
+
@uri.to_s.should == "https://example.com/"
|
4853
|
+
end
|
4854
|
+
|
4855
|
+
it "should heuristically parse to 'https://example.com/' " +
|
4856
|
+
"even with a scheme hint of 'ftp'" do
|
4857
|
+
@uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
|
4858
|
+
@uri.to_s.should == "https://example.com/"
|
4859
|
+
end
|
4860
|
+
end
|
4861
|
+
|
3973
4862
|
describe Addressable::URI, "when given the input " +
|
3974
4863
|
"'http://example.com/example.com/'" do
|
3975
4864
|
before do
|
@@ -4111,39 +5000,75 @@ describe Addressable::URI, "when assigning query values" do
|
|
4111
5000
|
|
4112
5001
|
it "should correctly assign {:a => 'a', :b => ['c', 'd', 'e']}" do
|
4113
5002
|
@uri.query_values = {:a => "a", :b => ["c", "d", "e"]}
|
4114
|
-
@uri.query.should == "a=a&b
|
5003
|
+
@uri.query.should == "a=a&b=c&b=d&b=e"
|
4115
5004
|
end
|
4116
5005
|
|
4117
|
-
it "should
|
4118
|
-
|
4119
|
-
|
4120
|
-
|
4121
|
-
}
|
4122
|
-
@uri.query.should == "a=a&b[0][c]=c&b[0][d]=d&b[1][e]=e&b[1][f]=f"
|
5006
|
+
it "should raise an error attempting to assign {'a' => {'b' => ['c']}}" do
|
5007
|
+
(lambda do
|
5008
|
+
@uri.query_values = { 'a' => {'b' => ['c'] } }
|
5009
|
+
end).should raise_error(TypeError)
|
4123
5010
|
end
|
4124
5011
|
|
4125
|
-
it "should
|
4126
|
-
"{:
|
4127
|
-
|
4128
|
-
|
4129
|
-
|
4130
|
-
@uri.query.should == "a=a&b[0][c]&b[0][d]=d&b[1][e]=e&b[1][f]=f"
|
5012
|
+
it "should raise an error attempting to assign " +
|
5013
|
+
"{:b => '2', :a => {:c => '1'}}" do
|
5014
|
+
(lambda do
|
5015
|
+
@uri.query_values = {:b => '2', :a => {:c => '1'}}
|
5016
|
+
end).should raise_error(TypeError)
|
4131
5017
|
end
|
4132
5018
|
|
4133
|
-
it "should
|
5019
|
+
it "should raise an error attempting to assign " +
|
5020
|
+
"{:a => 'a', :b => [{:c => 'c', :d => 'd'}, " +
|
5021
|
+
"{:e => 'e', :f => 'f'}]}" do
|
5022
|
+
(lambda do
|
5023
|
+
@uri.query_values = {
|
5024
|
+
:a => "a", :b => [{:c => "c", :d => "d"}, {:e => "e", :f => "f"}]
|
5025
|
+
}
|
5026
|
+
end).should raise_error(TypeError)
|
5027
|
+
end
|
5028
|
+
|
5029
|
+
it "should raise an error attempting to assign " +
|
5030
|
+
"{:a => 'a', :b => [{:c => true, :d => 'd'}, " +
|
5031
|
+
"{:e => 'e', :f => 'f'}]}" do
|
5032
|
+
(lambda do
|
5033
|
+
@uri.query_values = {
|
5034
|
+
:a => 'a', :b => [{:c => true, :d => 'd'}, {:e => 'e', :f => 'f'}]
|
5035
|
+
}
|
5036
|
+
end).should raise_error(TypeError)
|
5037
|
+
end
|
5038
|
+
|
5039
|
+
it "should raise an error attempting to assign " +
|
4134
5040
|
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
4135
|
-
|
4136
|
-
|
4137
|
-
|
4138
|
-
|
5041
|
+
(lambda do
|
5042
|
+
@uri.query_values = {
|
5043
|
+
:a => 'a', :b => {:c => true, :d => 'd'}
|
5044
|
+
}
|
5045
|
+
end).should raise_error(TypeError)
|
4139
5046
|
end
|
4140
5047
|
|
4141
|
-
it "should
|
4142
|
-
"{:a => 'a', :b => {:c => true, :d => 'd'}
|
4143
|
-
|
4144
|
-
|
4145
|
-
|
4146
|
-
|
5048
|
+
it "should raise an error attempting to assign " +
|
5049
|
+
"{:a => 'a', :b => {:c => true, :d => 'd'}}" do
|
5050
|
+
(lambda do
|
5051
|
+
@uri.query_values = {
|
5052
|
+
:a => 'a', :b => {:c => true, :d => 'd'}
|
5053
|
+
}
|
5054
|
+
end).should raise_error(TypeError)
|
5055
|
+
end
|
5056
|
+
|
5057
|
+
it "should correctly assign {:a => 1, :b => 1.5}" do
|
5058
|
+
@uri.query_values = { :a => 1, :b => 1.5 }
|
5059
|
+
@uri.query.should == "a=1&b=1.5"
|
5060
|
+
end
|
5061
|
+
|
5062
|
+
it "should raise an error attempting to assign " +
|
5063
|
+
"{:z => 1, :f => [2, {999.1 => [3,'4']}, ['h', 'i']], " +
|
5064
|
+
":a => {:b => ['c', 'd'], :e => true, :y => 0.5}}" do
|
5065
|
+
(lambda do
|
5066
|
+
@uri.query_values = {
|
5067
|
+
:z => 1,
|
5068
|
+
:f => [ 2, {999.1 => [3,'4']}, ['h', 'i'] ],
|
5069
|
+
:a => { :b => ['c', 'd'], :e => true, :y => 0.5 }
|
5070
|
+
}
|
5071
|
+
end).should raise_error(TypeError)
|
4147
5072
|
end
|
4148
5073
|
|
4149
5074
|
it "should correctly assign {}" do
|
@@ -4160,6 +5085,29 @@ describe Addressable::URI, "when assigning query values" do
|
|
4160
5085
|
@uri.query_values = {'ab' => 'c', :ab => 'a', :a => 'x'}
|
4161
5086
|
@uri.query.should == "a=x&ab=a&ab=c"
|
4162
5087
|
end
|
5088
|
+
|
5089
|
+
it "should correctly assign " +
|
5090
|
+
"[['b', 'c'], ['b', 'a'], ['a', 'a']]" do
|
5091
|
+
# Order can be guaranteed in this format, so preserve it.
|
5092
|
+
@uri.query_values = [['b', 'c'], ['b', 'a'], ['a', 'a']]
|
5093
|
+
@uri.query.should == "b=c&b=a&a=a"
|
5094
|
+
end
|
5095
|
+
|
5096
|
+
it "should preserve query string order" do
|
5097
|
+
query_string = (('a'..'z').to_a.reverse.map { |e| "#{e}=#{e}" }).join("&")
|
5098
|
+
@uri.query = query_string
|
5099
|
+
original_uri = @uri.to_s
|
5100
|
+
@uri.query_values = @uri.query_values(Array)
|
5101
|
+
@uri.to_s.should == original_uri
|
5102
|
+
end
|
5103
|
+
|
5104
|
+
describe 'when a hash with mixed types is assigned to query_values' do
|
5105
|
+
it 'should not raise an error' do
|
5106
|
+
pending 'Issue #94' do
|
5107
|
+
expect { subject.query_values = { "page" => "1", :page => 2 } }.to_not raise_error ArgumentError
|
5108
|
+
end
|
5109
|
+
end
|
5110
|
+
end
|
4163
5111
|
end
|
4164
5112
|
|
4165
5113
|
describe Addressable::URI, "when assigning path values" do
|
@@ -4169,8 +5117,11 @@ describe Addressable::URI, "when assigning path values" do
|
|
4169
5117
|
|
4170
5118
|
it "should correctly assign paths containing colons" do
|
4171
5119
|
@uri.path = "acct:bob@sporkmonger.com"
|
4172
|
-
|
5120
|
+
@uri.path.should == "acct:bob@sporkmonger.com"
|
4173
5121
|
@uri.normalize.to_str.should == "acct%2Fbob@sporkmonger.com"
|
5122
|
+
(lambda { @uri.to_s }).should raise_error(
|
5123
|
+
Addressable::URI::InvalidURIError
|
5124
|
+
)
|
4174
5125
|
end
|
4175
5126
|
|
4176
5127
|
it "should correctly assign paths containing colons" do
|