addressable 2.2.5 → 2.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ ## Addressable 2.2.6
2
+ - changed the way ambiguous paths are handled
3
+ - fixed bug with frozen URIs
4
+ - https supported in heuristic parsing
5
+
1
6
  ## Addressable 2.2.5
2
7
  - 'parsing' a pre-parsed URI object is now a dup operation
3
8
  - introduced conditional support for libidn
@@ -55,6 +55,22 @@ module Addressable
55
55
 
56
56
  URIREGEX = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/
57
57
 
58
+ PORT_MAPPING = {
59
+ "http" => 80,
60
+ "https" => 443,
61
+ "ftp" => 21,
62
+ "tftp" => 69,
63
+ "sftp" => 22,
64
+ "ssh" => 22,
65
+ "svn+ssh" => 22,
66
+ "telnet" => 23,
67
+ "nntp" => 119,
68
+ "gopher" => 70,
69
+ "wais" => 210,
70
+ "ldap" => 389,
71
+ "prospero" => 1525
72
+ }
73
+
58
74
  ##
59
75
  # Returns a URI object based on the parsed string.
60
76
  #
@@ -153,6 +169,8 @@ module Addressable
153
169
  case uri
154
170
  when /^http:\/+/
155
171
  uri.gsub!(/^http:\/+/, "http://")
172
+ when /^https:\/+/
173
+ uri.gsub!(/^https:\/+/, "https://")
156
174
  when /^feed:\/+http:\/+/
157
175
  uri.gsub!(/^feed:\/+http:\/+/, "feed:http://")
158
176
  when /^feed:\/+/
@@ -701,12 +719,32 @@ module Addressable
701
719
  end
702
720
  end
703
721
 
722
+ ##
723
+ # Freeze URI, initializing instance variables.
724
+ #
725
+ # @return [Addressable::URI] The frozen URI object.
726
+ def freeze
727
+ self.normalized_scheme
728
+ self.normalized_user
729
+ self.normalized_password
730
+ self.normalized_userinfo
731
+ self.normalized_host
732
+ self.normalized_port
733
+ self.normalized_authority
734
+ self.normalized_site
735
+ self.normalized_path
736
+ self.normalized_query
737
+ self.normalized_fragment
738
+ self.hash
739
+ super
740
+ end
741
+
704
742
  ##
705
743
  # The scheme component for this URI.
706
744
  #
707
745
  # @return [String] The scheme component.
708
746
  def scheme
709
- return @scheme ||= nil
747
+ return instance_variable_defined?(:@scheme) ? @scheme : nil
710
748
  end
711
749
 
712
750
  ##
@@ -714,18 +752,14 @@ module Addressable
714
752
  #
715
753
  # @return [String] The scheme component, normalized.
716
754
  def normalized_scheme
717
- @normalized_scheme ||= (begin
718
- if self.scheme != nil
719
- if self.scheme =~ /^\s*ssh\+svn\s*$/i
720
- "svn+ssh"
721
- else
722
- Addressable::URI.normalize_component(
723
- self.scheme.strip.downcase,
724
- Addressable::URI::CharacterClasses::SCHEME
725
- )
726
- end
755
+ self.scheme && @normalized_scheme ||= (begin
756
+ if self.scheme =~ /^\s*ssh\+svn\s*$/i
757
+ "svn+ssh"
727
758
  else
728
- nil
759
+ Addressable::URI.normalize_component(
760
+ self.scheme.strip.downcase,
761
+ Addressable::URI::CharacterClasses::SCHEME
762
+ )
729
763
  end
730
764
  end)
731
765
  end
@@ -760,7 +794,7 @@ module Addressable
760
794
  #
761
795
  # @return [String] The user component.
762
796
  def user
763
- return @user ||= nil
797
+ return instance_variable_defined?(:@user) ? @user : nil
764
798
  end
765
799
 
766
800
  ##
@@ -768,19 +802,15 @@ module Addressable
768
802
  #
769
803
  # @return [String] The user component, normalized.
770
804
  def normalized_user
771
- @normalized_user ||= (begin
772
- if self.user
773
- if normalized_scheme =~ /https?/ && self.user.strip.empty? &&
774
- (!self.password || self.password.strip.empty?)
775
- nil
776
- else
777
- Addressable::URI.normalize_component(
778
- self.user.strip,
779
- Addressable::URI::CharacterClasses::UNRESERVED
780
- )
781
- end
782
- else
805
+ self.user && @normalized_user ||= (begin
806
+ if normalized_scheme =~ /https?/ && self.user.strip.empty? &&
807
+ (!self.password || self.password.strip.empty?)
783
808
  nil
809
+ else
810
+ Addressable::URI.normalize_component(
811
+ self.user.strip,
812
+ Addressable::URI::CharacterClasses::UNRESERVED
813
+ )
784
814
  end
785
815
  end)
786
816
  end
@@ -796,8 +826,7 @@ module Addressable
796
826
  @user = new_user ? new_user.to_str : nil
797
827
 
798
828
  # You can't have a nil user with a non-nil password
799
- @password ||= nil
800
- if @password != nil
829
+ if password != nil
801
830
  @user = EMPTYSTR if @user.nil?
802
831
  end
803
832
 
@@ -818,7 +847,7 @@ module Addressable
818
847
  #
819
848
  # @return [String] The password component.
820
849
  def password
821
- return @password ||= nil
850
+ return instance_variable_defined?(:@password) ? @password : nil
822
851
  end
823
852
 
824
853
  ##
@@ -826,19 +855,15 @@ module Addressable
826
855
  #
827
856
  # @return [String] The password component, normalized.
828
857
  def normalized_password
829
- @normalized_password ||= (begin
830
- if self.password
831
- if normalized_scheme =~ /https?/ && self.password.strip.empty? &&
832
- (!self.user || self.user.strip.empty?)
833
- nil
834
- else
835
- Addressable::URI.normalize_component(
836
- self.password.strip,
837
- Addressable::URI::CharacterClasses::UNRESERVED
838
- )
839
- end
840
- else
858
+ self.password && @normalized_password ||= (begin
859
+ if self.normalized_scheme =~ /https?/ && self.password.strip.empty? &&
860
+ (!self.user || self.user.strip.empty?)
841
861
  nil
862
+ else
863
+ Addressable::URI.normalize_component(
864
+ self.password.strip,
865
+ Addressable::URI::CharacterClasses::UNRESERVED
866
+ )
842
867
  end
843
868
  end)
844
869
  end
@@ -878,12 +903,10 @@ module Addressable
878
903
  #
879
904
  # @return [String] The userinfo component.
880
905
  def userinfo
881
- @userinfo ||= (begin
882
- current_user = self.user
883
- current_password = self.password
884
- if !current_user && !current_password
885
- nil
886
- elsif current_user && current_password
906
+ current_user = self.user
907
+ current_password = self.password
908
+ (current_user || current_password) && @userinfo ||= (begin
909
+ if current_user && current_password
887
910
  "#{current_user}:#{current_password}"
888
911
  elsif current_user && !current_password
889
912
  "#{current_user}"
@@ -896,7 +919,7 @@ module Addressable
896
919
  #
897
920
  # @return [String] The userinfo component, normalized.
898
921
  def normalized_userinfo
899
- @normalized_userinfo ||= (begin
922
+ self.userinfo && @normalized_userinfo ||= (begin
900
923
  current_user = self.normalized_user
901
924
  current_password = self.normalized_password
902
925
  if !current_user && !current_password
@@ -944,7 +967,7 @@ module Addressable
944
967
  #
945
968
  # @return [String] The host component.
946
969
  def host
947
- return @host ||= nil
970
+ return instance_variable_defined?(:@host) ? @host : nil
948
971
  end
949
972
 
950
973
  ##
@@ -952,7 +975,7 @@ module Addressable
952
975
  #
953
976
  # @return [String] The host component, normalized.
954
977
  def normalized_host
955
- @normalized_host ||= (begin
978
+ self.host && @normalized_host ||= (begin
956
979
  if self.host != nil
957
980
  if !self.host.strip.empty?
958
981
  result = ::Addressable::IDNA.to_ascii(
@@ -998,20 +1021,16 @@ module Addressable
998
1021
  #
999
1022
  # @return [String] The authority component.
1000
1023
  def authority
1001
- @authority ||= (begin
1002
- if self.host.nil?
1003
- nil
1004
- else
1005
- authority = ""
1006
- if self.userinfo != nil
1007
- authority << "#{self.userinfo}@"
1008
- end
1009
- authority << self.host
1010
- if self.port != nil
1011
- authority << ":#{self.port}"
1012
- end
1013
- authority
1024
+ self.host && @authority ||= (begin
1025
+ authority = ""
1026
+ if self.userinfo != nil
1027
+ authority << "#{self.userinfo}@"
1014
1028
  end
1029
+ authority << self.host
1030
+ if self.port != nil
1031
+ authority << ":#{self.port}"
1032
+ end
1033
+ authority
1015
1034
  end)
1016
1035
  end
1017
1036
 
@@ -1020,20 +1039,16 @@ module Addressable
1020
1039
  #
1021
1040
  # @return [String] The authority component, normalized.
1022
1041
  def normalized_authority
1023
- @normalized_authority ||= (begin
1024
- if self.normalized_host.nil?
1025
- nil
1026
- else
1027
- authority = ""
1028
- if self.normalized_userinfo != nil
1029
- authority << "#{self.normalized_userinfo}@"
1030
- end
1031
- authority << self.normalized_host
1032
- if self.normalized_port != nil
1033
- authority << ":#{self.normalized_port}"
1034
- end
1035
- authority
1042
+ self.authority && @normalized_authority ||= (begin
1043
+ authority = ""
1044
+ if self.normalized_userinfo != nil
1045
+ authority << "#{self.normalized_userinfo}@"
1046
+ end
1047
+ authority << self.normalized_host
1048
+ if self.normalized_port != nil
1049
+ authority << ":#{self.normalized_port}"
1036
1050
  end
1051
+ authority
1037
1052
  end)
1038
1053
  end
1039
1054
 
@@ -1065,7 +1080,6 @@ module Addressable
1065
1080
  self.port = defined?(new_port) ? new_port : nil
1066
1081
 
1067
1082
  # Reset dependant values
1068
- @inferred_port = nil
1069
1083
  @userinfo = nil
1070
1084
  @normalized_userinfo = nil
1071
1085
  @uri_string = nil
@@ -1106,21 +1120,7 @@ module Addressable
1106
1120
  # numbers. Adding new schemes to this hash, as necessary, will allow
1107
1121
  # for better URI normalization.
1108
1122
  def self.port_mapping
1109
- @port_mapping ||= {
1110
- "http" => 80,
1111
- "https" => 443,
1112
- "ftp" => 21,
1113
- "tftp" => 69,
1114
- "sftp" => 22,
1115
- "ssh" => 22,
1116
- "svn+ssh" => 22,
1117
- "telnet" => 23,
1118
- "nntp" => 119,
1119
- "gopher" => 70,
1120
- "wais" => 210,
1121
- "ldap" => 389,
1122
- "prospero" => 1525
1123
- }
1123
+ PORT_MAPPING
1124
1124
  end
1125
1125
 
1126
1126
  ##
@@ -1130,7 +1130,7 @@ module Addressable
1130
1130
  #
1131
1131
  # @return [Integer] The port component.
1132
1132
  def port
1133
- return @port ||= nil
1133
+ return instance_variable_defined?(:@port) ? @port : nil
1134
1134
  end
1135
1135
 
1136
1136
  ##
@@ -1138,13 +1138,11 @@ module Addressable
1138
1138
  #
1139
1139
  # @return [Integer] The port component, normalized.
1140
1140
  def normalized_port
1141
- @normalized_port ||= (begin
1142
- if URI.port_mapping[normalized_scheme] == self.port
1143
- nil
1144
- else
1145
- self.port
1146
- end
1147
- end)
1141
+ if URI.port_mapping[self.normalized_scheme] == self.port
1142
+ nil
1143
+ else
1144
+ self.port
1145
+ end
1148
1146
  end
1149
1147
 
1150
1148
  ##
@@ -1165,7 +1163,6 @@ module Addressable
1165
1163
 
1166
1164
  # Reset dependant values
1167
1165
  @authority = nil
1168
- @inferred_port = nil
1169
1166
  @normalized_port = nil
1170
1167
  @uri_string = nil
1171
1168
  @hash = nil
@@ -1181,17 +1178,15 @@ module Addressable
1181
1178
  #
1182
1179
  # @return [Integer] The inferred port component.
1183
1180
  def inferred_port
1184
- @inferred_port ||= (begin
1185
- if port.to_i == 0
1186
- if scheme
1187
- URI.port_mapping[scheme.strip.downcase]
1188
- else
1189
- nil
1190
- end
1181
+ if self.port.to_i == 0
1182
+ if self.scheme
1183
+ URI.port_mapping[self.scheme.strip.downcase]
1191
1184
  else
1192
- port.to_i
1185
+ nil
1193
1186
  end
1194
- end)
1187
+ else
1188
+ self.port.to_i
1189
+ end
1195
1190
  end
1196
1191
 
1197
1192
  ##
@@ -1204,15 +1199,11 @@ module Addressable
1204
1199
  #
1205
1200
  # @return [String] The components that identify a site.
1206
1201
  def site
1207
- @site ||= (begin
1208
- if self.scheme || self.authority
1209
- site_string = ""
1210
- site_string << "#{self.scheme}:" if self.scheme != nil
1211
- site_string << "//#{self.authority}" if self.authority != nil
1212
- site_string
1213
- else
1214
- nil
1215
- end
1202
+ (self.scheme || self.authority) && @site ||= (begin
1203
+ site_string = ""
1204
+ site_string << "#{self.scheme}:" if self.scheme != nil
1205
+ site_string << "//#{self.authority}" if self.authority != nil
1206
+ site_string
1216
1207
  end)
1217
1208
  end
1218
1209
 
@@ -1226,19 +1217,15 @@ module Addressable
1226
1217
  #
1227
1218
  # @return [String] The normalized components that identify a site.
1228
1219
  def normalized_site
1229
- @site ||= (begin
1230
- if self.normalized_scheme || self.normalized_authority
1231
- site_string = ""
1232
- if self.normalized_scheme != nil
1233
- site_string << "#{self.normalized_scheme}:"
1234
- end
1235
- if self.normalized_authority != nil
1236
- site_string << "//#{self.normalized_authority}"
1237
- end
1238
- site_string
1239
- else
1240
- nil
1220
+ self.site && @normalized_site ||= (begin
1221
+ site_string = ""
1222
+ if self.normalized_scheme != nil
1223
+ site_string << "#{self.normalized_scheme}:"
1241
1224
  end
1225
+ if self.normalized_authority != nil
1226
+ site_string << "//#{self.normalized_authority}"
1227
+ end
1228
+ site_string
1242
1229
  end)
1243
1230
  end
1244
1231
 
@@ -1269,8 +1256,7 @@ module Addressable
1269
1256
  #
1270
1257
  # @return [String] The path component.
1271
1258
  def path
1272
- @path ||= EMPTYSTR
1273
- return @path
1259
+ return instance_variable_defined?(:@path) ? @path : EMPTYSTR
1274
1260
  end
1275
1261
 
1276
1262
  NORMPATH = /^(?!\/)[^\/:]*:.*$/
@@ -1280,14 +1266,14 @@ module Addressable
1280
1266
  # @return [String] The path component, normalized.
1281
1267
  def normalized_path
1282
1268
  @normalized_path ||= (begin
1283
- if self.scheme == nil && self.path != nil && !self.path.empty? &&
1284
- self.path =~ NORMPATH
1269
+ path = self.path.to_s
1270
+ if self.scheme == nil && path =~ NORMPATH
1285
1271
  # Relative paths with colons in the first segment are ambiguous.
1286
- self.path.sub!(":", "%2F")
1272
+ path = path.sub(":", "%2F")
1287
1273
  end
1288
1274
  # String#split(delimeter, -1) uses the more strict splitting behavior
1289
1275
  # found by default in Python.
1290
- result = (self.path.strip.split(SLASH, -1).map do |segment|
1276
+ result = (path.strip.split(SLASH, -1).map do |segment|
1291
1277
  Addressable::URI.normalize_component(
1292
1278
  segment,
1293
1279
  Addressable::URI::CharacterClasses::PCHAR
@@ -1346,7 +1332,7 @@ module Addressable
1346
1332
  #
1347
1333
  # @return [String] The query component.
1348
1334
  def query
1349
- return @query ||= nil
1335
+ return instance_variable_defined?(:@query) ? @query : nil
1350
1336
  end
1351
1337
 
1352
1338
  ##
@@ -1354,17 +1340,13 @@ module Addressable
1354
1340
  #
1355
1341
  # @return [String] The query component, normalized.
1356
1342
  def normalized_query
1357
- @normalized_query ||= (begin
1358
- if self.query
1359
- (self.query.split("&", -1).map do |pair|
1360
- Addressable::URI.normalize_component(
1361
- pair,
1362
- Addressable::URI::CharacterClasses::QUERY.sub("\\&", "")
1363
- )
1364
- end).join("&")
1365
- else
1366
- nil
1367
- end
1343
+ self.query && @normalized_query ||= (begin
1344
+ (self.query.split("&", -1).map do |pair|
1345
+ Addressable::URI.normalize_component(
1346
+ pair,
1347
+ Addressable::URI::CharacterClasses::QUERY.sub("\\&", "")
1348
+ )
1349
+ end).join("&")
1368
1350
  end)
1369
1351
  end
1370
1352
 
@@ -1595,7 +1577,7 @@ module Addressable
1595
1577
  #
1596
1578
  # @return [String] The fragment component.
1597
1579
  def fragment
1598
- return @fragment ||= nil
1580
+ return instance_variable_defined?(:@fragment) ? @fragment : nil
1599
1581
  end
1600
1582
 
1601
1583
  ##
@@ -1603,15 +1585,11 @@ module Addressable
1603
1585
  #
1604
1586
  # @return [String] The fragment component, normalized.
1605
1587
  def normalized_fragment
1606
- @normalized_fragment ||= (begin
1607
- if self.fragment
1608
- Addressable::URI.normalize_component(
1609
- self.fragment.strip,
1610
- Addressable::URI::CharacterClasses::FRAGMENT
1611
- )
1612
- else
1613
- nil
1614
- end
1588
+ self.fragment && @normalized_fragment ||= (begin
1589
+ Addressable::URI.normalize_component(
1590
+ self.fragment.strip,
1591
+ Addressable::URI::CharacterClasses::FRAGMENT
1592
+ )
1615
1593
  end)
1616
1594
  end
1617
1595
 
@@ -2111,6 +2089,11 @@ module Addressable
2111
2089
  #
2112
2090
  # @return [String] The URI's <code>String</code> representation.
2113
2091
  def to_s
2092
+ if self.scheme == nil && self.path != nil && !self.path.empty? &&
2093
+ self.path =~ NORMPATH
2094
+ raise InvalidURIError,
2095
+ "Cannot assemble URI string with ambiguous path: '#{self.path}'"
2096
+ end
2114
2097
  @uri_string ||= (begin
2115
2098
  uri_string = ""
2116
2099
  uri_string << "#{self.scheme}:" if self.scheme != nil
@@ -22,7 +22,7 @@ if !defined?(Addressable::VERSION)
22
22
  module VERSION
23
23
  MAJOR = 2
24
24
  MINOR = 2
25
- TINY = 5
25
+ TINY = 6
26
26
 
27
27
  STRING = [MAJOR, MINOR, TINY].join('.')
28
28
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # Copyright (C) 2006-2011 Bob Aman
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # Copyright (C) 2006-2011 Bob Aman
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1165,11 +1166,11 @@ describe Addressable::URI, "when given the mapping supplied in " +
1165
1166
 
1166
1167
  it "should result in ':%E1%B9%A1:%E1%B9%A1:' " +
1167
1168
  "when used to expand '{-neg|:|corge}{-suffix|:|plugh}'" do
1169
+ # Note: We need to check the path, because technically, this is an
1170
+ # invalid URI.
1168
1171
  Addressable::Template.new(
1169
1172
  "{-neg|:|corge}{-suffix|:|plugh}"
1170
- ).expand(
1171
- @mapping
1172
- ).to_s.should == ":%E1%B9%A1:%E1%B9%A1:"
1173
+ ).expand(@mapping).path.should == ":%E1%B9%A1:%E1%B9%A1:"
1173
1174
  end
1174
1175
 
1175
1176
  it "should result in '../ben%20%26%20jerrys/' " +
@@ -1192,11 +1193,11 @@ describe Addressable::URI, "when given the mapping supplied in " +
1192
1193
 
1193
1194
  it "should result in ':200:' " +
1194
1195
  "when used to expand ':{1-a_b.c}:'" do
1196
+ # Note: We need to check the path, because technically, this is an
1197
+ # invalid URI.
1195
1198
  Addressable::Template.new(
1196
1199
  ":{1-a_b.c}:"
1197
- ).expand(
1198
- @mapping
1199
- ).to_s.should == ":200:"
1200
+ ).expand(@mapping).path.should == ":200:"
1200
1201
  end
1201
1202
  end
1202
1203
 
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # Copyright (C) 2006-2011 Bob Aman
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -205,6 +206,108 @@ describe Addressable::URI, "when created from nil components" do
205
206
  end
206
207
  end
207
208
 
209
+ describe Addressable::URI, "when frozen" do
210
+ before do
211
+ @uri = Addressable::URI.new.freeze
212
+ end
213
+
214
+ it "returns nil for #scheme" do
215
+ @uri.scheme.should == nil
216
+ end
217
+
218
+ it "returns nil for #normalized_scheme" do
219
+ @uri.normalized_scheme.should == nil
220
+ end
221
+
222
+ it "returns nil for #user" do
223
+ @uri.user .should == nil
224
+ end
225
+
226
+ it "returns nil for #normalized_user" do
227
+ @uri.normalized_user.should == nil
228
+ end
229
+
230
+ it "returns nil for #password" do
231
+ @uri.password.should == nil
232
+ end
233
+
234
+ it "returns nil for #normalized_password" do
235
+ @uri.normalized_password.should == nil
236
+ end
237
+
238
+ it "returns nil for #userinfo" do
239
+ @uri.userinfo.should == nil
240
+ end
241
+
242
+ it "returns nil for #normalized_userinfo" do
243
+ @uri.normalized_userinfo.should == nil
244
+ end
245
+
246
+ it "returns nil for #host" do
247
+ @uri.host.should == nil
248
+ end
249
+
250
+ it "returns nil for #normalized_host" do
251
+ @uri.normalized_host.should == nil
252
+ end
253
+
254
+ it "returns nil for #authority" do
255
+ @uri.authority.should == nil
256
+ end
257
+
258
+ it "returns nil for #normalized_authority" do
259
+ @uri.normalized_authority.should == nil
260
+ end
261
+
262
+ it "returns nil for #port" do
263
+ @uri.port.should == nil
264
+ end
265
+
266
+ it "returns nil for #normalized_port" do
267
+ @uri.normalized_port.should == nil
268
+ end
269
+
270
+ it "returns nil for #site" do
271
+ @uri.site.should == nil
272
+ end
273
+
274
+ it "returns nil for #normalized_site" do
275
+ @uri.normalized_site.should == nil
276
+ end
277
+
278
+ it "returns '' for #path" do
279
+ @uri.path.should == ''
280
+ end
281
+
282
+ it "returns '' for #normalized_path" do
283
+ @uri.normalized_path.should == ''
284
+ end
285
+
286
+ it "returns nil for #query" do
287
+ @uri.query.should == nil
288
+ end
289
+
290
+ it "returns nil for #normalized_query" do
291
+ @uri.normalized_query.should == nil
292
+ end
293
+
294
+ it "returns nil for #fragment" do
295
+ @uri.fragment.should == nil
296
+ end
297
+
298
+ it "returns nil for #normalized_fragment" do
299
+ @uri.normalized_fragment.should == nil
300
+ end
301
+
302
+ it "returns #hash" do
303
+ @uri.hash.should_not be nil
304
+ end
305
+
306
+ it "returns #to_s" do
307
+ @uri.to_s.should == ''
308
+ end
309
+ end
310
+
208
311
  describe Addressable::URI, "when created from string components" do
209
312
  before do
210
313
  @uri = Addressable::URI.new(
@@ -3953,15 +4056,15 @@ describe Addressable::URI, "when given a Windows root directory" do
3953
4056
  end
3954
4057
  end
3955
4058
 
3956
- describe Addressable::URI, "when given the path '/home/user/'" do
4059
+ describe Addressable::URI, "when given the path '/one/two/'" do
3957
4060
  before do
3958
- @path = '/home/user/'
4061
+ @path = '/one/two/'
3959
4062
  end
3960
4063
 
3961
4064
  it "should convert to " +
3962
- "\'file:///home/user/\'" do
4065
+ "\'file:///one/two/\'" do
3963
4066
  @uri = Addressable::URI.convert_path(@path)
3964
- @uri.to_str.should == "file:///home/user/"
4067
+ @uri.to_str.should == "file:///one/two/"
3965
4068
  end
3966
4069
 
3967
4070
  it "should have an origin of 'file://'" do
@@ -4352,8 +4455,23 @@ describe Addressable::URI, "when given the input " +
4352
4455
  @uri = Addressable::URI.heuristic_parse(@input)
4353
4456
  @uri.to_s.should == "http://example.com/"
4354
4457
  end
4458
+
4459
+ it "should not raise error when frozen" do
4460
+ lambda {Addressable::URI.heuristic_parse(@input).freeze.to_s}.should_not raise_error
4461
+ end
4355
4462
  end
4356
4463
 
4464
+ describe Addressable::URI, "when given the input " +
4465
+ "'https://example.com/'" do
4466
+ before do
4467
+ @input = "https://example.com/"
4468
+ end
4469
+
4470
+ it "should heuristically parse to 'https://example.com/'" do
4471
+ @uri = Addressable::URI.heuristic_parse(@input)
4472
+ @uri.to_s.should == "https://example.com/"
4473
+ end
4474
+ end
4357
4475
 
4358
4476
  describe Addressable::URI, "when given the input " +
4359
4477
  "'http:example.com/'" do
@@ -4373,6 +4491,24 @@ describe Addressable::URI, "when given the input " +
4373
4491
  end
4374
4492
  end
4375
4493
 
4494
+ describe Addressable::URI, "when given the input " +
4495
+ "'https:example.com/'" do
4496
+ before do
4497
+ @input = "https:example.com/"
4498
+ end
4499
+
4500
+ it "should heuristically parse to 'https://example.com/'" do
4501
+ @uri = Addressable::URI.heuristic_parse(@input)
4502
+ @uri.to_s.should == "https://example.com/"
4503
+ end
4504
+
4505
+ it "should heuristically parse to 'https://example.com/' " +
4506
+ "even with a scheme hint of 'ftp'" do
4507
+ @uri = Addressable::URI.heuristic_parse(@input, {:scheme => 'ftp'})
4508
+ @uri.to_s.should == "https://example.com/"
4509
+ end
4510
+ end
4511
+
4376
4512
  describe Addressable::URI, "when given the input " +
4377
4513
  "'http://example.com/example.com/'" do
4378
4514
  before do
@@ -4587,8 +4723,11 @@ describe Addressable::URI, "when assigning path values" do
4587
4723
 
4588
4724
  it "should correctly assign paths containing colons" do
4589
4725
  @uri.path = "acct:bob@sporkmonger.com"
4590
- Addressable::URI.parse(@uri.normalize.to_str).path.should == @uri.path
4726
+ @uri.path.should == "acct:bob@sporkmonger.com"
4591
4727
  @uri.normalize.to_str.should == "acct%2Fbob@sporkmonger.com"
4728
+ (lambda { @uri.to_s }).should raise_error(
4729
+ Addressable::URI::InvalidURIError
4730
+ )
4592
4731
  end
4593
4732
 
4594
4733
  it "should correctly assign paths containing colons" do
@@ -6,9 +6,13 @@ namespace :spec do
6
6
 
7
7
  t.rcov = RCOV_ENABLED
8
8
  t.rcov_opts = [
9
+ '--exclude', 'lib\\/compat',
9
10
  '--exclude', 'spec',
11
+ '--exclude', '\\.rvm\\/gems',
10
12
  '--exclude', '1\\.8\\/gems',
11
13
  '--exclude', '1\\.9\\/gems',
14
+ '--exclude', '\\.rvm',
15
+ '--exclude', '\\/Library\\/Ruby',
12
16
  '--exclude', 'addressable\\/idna' # environment dependant
13
17
  ]
14
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
4
+ hash: 11
5
+ prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 5
10
- version: 2.2.5
9
+ - 6
10
+ version: 2.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bob Aman
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-09 00:00:00 -07:00
18
+ date: 2011-05-12 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  requirements: []
149
149
 
150
150
  rubyforge_project: addressable
151
- rubygems_version: 1.3.7
151
+ rubygems_version: 1.4.1
152
152
  signing_key:
153
153
  specification_version: 3
154
154
  summary: URI Implementation