addressable 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ === Addressable 2.0.1
2
+ * fixed issue with query string assignment
3
+ * fixed issue with improperly encoded components
4
+
1
5
  === Addressable 2.0.0
2
6
  * the initialize method now takes an options hash as its only parameter
3
7
  * added query_values method to URI class
data/README CHANGED
@@ -14,11 +14,25 @@ Example usage:
14
14
  uri.path
15
15
  #=> "/path/to/resource/"
16
16
 
17
+ uri = Addressable::URI.parse("http://www.詹姆斯.com/")
18
+ uri.normalize
19
+ #=> #<Addressable::URI:0xc9a4c8 URI:http://www.xn--8ws00zhy3a.com/>
20
+
17
21
  Addressable::URI.expand_template("http://example.com/{-list|+|query}/", {
18
22
  "query" => "an example query".split(" ")
19
23
  })
20
24
  #=> #<Addressable::URI:0xc9d95c URI:http://example.com/an+example+query/>
21
25
 
22
- uri = Addressable::URI.parse("http://www.詹姆斯.com/")
23
- uri.normalize
24
- #=> #<Addressable::URI:0xc9a4c8 URI:http://www.xn--8ws00zhy3a.com/>
26
+ Addressable::URI.parse(
27
+ "http://example.com/a/b/c/?one=1&two=2#foo"
28
+ ).extract_mapping(
29
+ "http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}"
30
+ )
31
+ #=>
32
+ # {
33
+ # "host" => "example.com",
34
+ # "segments" => ["a", "b", "c"],
35
+ # "one" => "1",
36
+ # "two" => "2",
37
+ # "fragment" => "foo"
38
+ # }
@@ -990,7 +990,8 @@ module Addressable
990
990
  end
991
991
  if ![String, ::Addressable::URI].include?(returning)
992
992
  raise TypeError,
993
- "Expected String or Addressable::URI, got #{returning.inspect}"
993
+ "Expected Class (String or Addressable::URI), " +
994
+ "got #{returning.inspect}"
994
995
  end
995
996
  result = uri.to_str.gsub(/%[0-9a-f]{2}/i) do |sequence|
996
997
  sequence[1..3].to_i(16).chr
@@ -1030,7 +1031,8 @@ module Addressable
1030
1031
  end
1031
1032
  if ![String, ::Addressable::URI].include?(returning)
1032
1033
  raise TypeError,
1033
- "Expected String or Addressable::URI, got #{returning.inspect}"
1034
+ "Expected Class (String or Addressable::URI), " +
1035
+ "got #{returning.inspect}"
1034
1036
  end
1035
1037
  uri_object = uri.kind_of?(self) ? uri : self.parse(uri.to_str)
1036
1038
  encoded_uri = Addressable::URI.new(
@@ -1077,7 +1079,8 @@ module Addressable
1077
1079
  end
1078
1080
  if ![String, ::Addressable::URI].include?(returning)
1079
1081
  raise TypeError,
1080
- "Expected String or Addressable::URI, got #{returning.inspect}"
1082
+ "Expected Class (String or Addressable::URI), " +
1083
+ "got #{returning.inspect}"
1081
1084
  end
1082
1085
  uri_object = uri.kind_of?(self) ? uri : self.parse(uri.to_str)
1083
1086
  components = {
@@ -1099,9 +1102,9 @@ module Addressable
1099
1102
  :scheme => self.encode_component(components[:scheme],
1100
1103
  Addressable::URI::CharacterClasses::SCHEME),
1101
1104
  :user => self.encode_component(components[:user],
1102
- Addressable::URI::CharacterClasses::AUTHORITY),
1105
+ Addressable::URI::CharacterClasses::UNRESERVED),
1103
1106
  :password => self.encode_component(components[:password],
1104
- Addressable::URI::CharacterClasses::AUTHORITY),
1107
+ Addressable::URI::CharacterClasses::UNRESERVED),
1105
1108
  :host => components[:host],
1106
1109
  :port => components[:port],
1107
1110
  :path => self.encode_component(components[:path],
@@ -1245,7 +1248,12 @@ module Addressable
1245
1248
  if self.scheme =~ /^\s*ssh\+svn\s*$/i
1246
1249
  "svn+ssh"
1247
1250
  else
1248
- self.scheme.strip.downcase
1251
+ Addressable::URI.encode_component(
1252
+ Addressable::IDNA.unicode_normalize_kc(
1253
+ Addressable::URI.unencode_component(
1254
+ self.scheme.strip.downcase)),
1255
+ Addressable::URI::CharacterClasses::SCHEME
1256
+ )
1249
1257
  end
1250
1258
  else
1251
1259
  nil
@@ -1284,7 +1292,11 @@ module Addressable
1284
1292
  (!self.password || self.password.strip == "")
1285
1293
  nil
1286
1294
  else
1287
- self.user.strip
1295
+ Addressable::URI.encode_component(
1296
+ Addressable::IDNA.unicode_normalize_kc(
1297
+ Addressable::URI.unencode_component(self.user.strip)),
1298
+ Addressable::URI::CharacterClasses::UNRESERVED
1299
+ )
1288
1300
  end
1289
1301
  else
1290
1302
  nil
@@ -1333,7 +1345,11 @@ module Addressable
1333
1345
  (!self.user || self.user.strip == "")
1334
1346
  nil
1335
1347
  else
1336
- self.password.strip
1348
+ Addressable::URI.encode_component(
1349
+ Addressable::IDNA.unicode_normalize_kc(
1350
+ Addressable::URI.unencode_component(self.password.strip)),
1351
+ Addressable::URI::CharacterClasses::UNRESERVED
1352
+ )
1337
1353
  end
1338
1354
  else
1339
1355
  nil
@@ -1608,6 +1624,9 @@ module Addressable
1608
1624
  #
1609
1625
  # @param [String, Integer, #to_s] new_port The new port component.
1610
1626
  def port=(new_port)
1627
+ if new_port != nil && new_port.respond_to?(:to_str)
1628
+ new_port = Addressable::URI.unencode_component(new_port.to_str)
1629
+ end
1611
1630
  if new_port != nil && !(new_port.to_s =~ /^\d+$/)
1612
1631
  raise InvalidURIError,
1613
1632
  "Invalid port number: #{new_port.inspect}"
@@ -1659,7 +1678,12 @@ module Addressable
1659
1678
  # @return [String] The path component, normalized.
1660
1679
  def normalized_path
1661
1680
  @normalized_path ||= (begin
1662
- result = self.class.normalize_path(self.path.strip)
1681
+ result = Addressable::URI.encode_component(
1682
+ Addressable::IDNA.unicode_normalize_kc(
1683
+ Addressable::URI.unencode_component(self.path.strip)),
1684
+ Addressable::URI::CharacterClasses::PATH
1685
+ )
1686
+ result = self.class.normalize_path(result)
1663
1687
  if result == "" &&
1664
1688
  ["http", "https", "ftp", "tftp"].include?(self.normalized_scheme)
1665
1689
  result = "/"
@@ -1714,7 +1738,17 @@ module Addressable
1714
1738
  #
1715
1739
  # @return [String] The query component, normalized.
1716
1740
  def normalized_query
1717
- @normalized_query ||= (self.query ? self.query.strip : nil)
1741
+ @normalized_query ||= (begin
1742
+ if self.query
1743
+ Addressable::URI.encode_component(
1744
+ Addressable::IDNA.unicode_normalize_kc(
1745
+ Addressable::URI.unencode_component(self.query.strip)),
1746
+ Addressable::URI::CharacterClasses::QUERY
1747
+ )
1748
+ else
1749
+ nil
1750
+ end
1751
+ end)
1718
1752
  end
1719
1753
 
1720
1754
  ##
@@ -1722,7 +1756,7 @@ module Addressable
1722
1756
  #
1723
1757
  # @param [String, #to_str] new_query The new query component.
1724
1758
  def query=(new_query)
1725
- @query = new_query.to_str
1759
+ @query = new_query ? new_query.to_str : nil
1726
1760
 
1727
1761
  # Reset dependant values
1728
1762
  @normalized_query = nil
@@ -1840,7 +1874,17 @@ module Addressable
1840
1874
  #
1841
1875
  # @return [String] The fragment component, normalized.
1842
1876
  def normalized_fragment
1843
- @normalized_fragment ||= (self.fragment ? self.fragment.strip : nil)
1877
+ @normalized_fragment ||= (begin
1878
+ if self.fragment
1879
+ Addressable::URI.encode_component(
1880
+ Addressable::IDNA.unicode_normalize_kc(
1881
+ Addressable::URI.unencode_component(self.fragment.strip)),
1882
+ Addressable::URI::CharacterClasses::FRAGMENT
1883
+ )
1884
+ else
1885
+ nil
1886
+ end
1887
+ end)
1844
1888
  end
1845
1889
 
1846
1890
  ##
@@ -2171,15 +2215,12 @@ module Addressable
2171
2215
  end
2172
2216
  end
2173
2217
 
2174
- return Addressable::URI.normalized_encode(
2175
- Addressable::URI.new(
2176
- :scheme => normalized_scheme,
2177
- :authority => normalized_authority,
2178
- :path => normalized_path,
2179
- :query => normalized_query,
2180
- :fragment => normalized_fragment
2181
- ),
2182
- ::Addressable::URI
2218
+ return Addressable::URI.new(
2219
+ :scheme => normalized_scheme,
2220
+ :authority => normalized_authority,
2221
+ :path => normalized_path,
2222
+ :query => normalized_query,
2223
+ :fragment => normalized_fragment
2183
2224
  )
2184
2225
  end
2185
2226
 
@@ -27,7 +27,7 @@ if !defined?(Addressable::VERSION)
27
27
  module VERSION #:nodoc:
28
28
  MAJOR = 2
29
29
  MINOR = 0
30
- TINY = 0
30
+ TINY = 1
31
31
 
32
32
  STRING = [MAJOR, MINOR, TINY].join('.')
33
33
  end
@@ -584,6 +584,14 @@ describe Addressable::URI, " when parsed from " +
584
584
  @uri.to_s.should == "http://newuser@example.com"
585
585
  end
586
586
 
587
+ it "should have the correct username after assignment" do
588
+ @uri.user = "user@123!"
589
+ @uri.user.should == "user@123!"
590
+ @uri.normalized_user.should == "user%40123%21"
591
+ @uri.password.should == nil
592
+ @uri.normalize.to_s.should == "http://user%40123%21@example.com/"
593
+ end
594
+
587
595
  it "should have the correct password after assignment" do
588
596
  @uri.password = "newpass"
589
597
  @uri.password.should == "newpass"
@@ -591,6 +599,14 @@ describe Addressable::URI, " when parsed from " +
591
599
  @uri.to_s.should == "http://:newpass@example.com"
592
600
  end
593
601
 
602
+ it "should have the correct password after assignment" do
603
+ @uri.password = "secret@123!"
604
+ @uri.password.should == "secret@123!"
605
+ @uri.normalized_password.should == "secret%40123%21"
606
+ @uri.user.should == ""
607
+ @uri.normalize.to_s.should == "http://:secret%40123%21@example.com/"
608
+ end
609
+
594
610
  it "should have the correct user/pass after repeated assignment" do
595
611
  @uri.user = nil
596
612
  @uri.user.should == nil
@@ -831,6 +847,8 @@ describe Addressable::URI, " when parsed from " +
831
847
  it "should not change if encoded with the normalizing algorithm" do
832
848
  Addressable::URI.normalized_encode(@uri).to_s.should ==
833
849
  "http://example.com/%C3%87"
850
+ Addressable::URI.normalized_encode(@uri, Addressable::URI).to_s.should ===
851
+ "http://example.com/%C3%87"
834
852
  end
835
853
 
836
854
  it "should raise an error if encoding with an unexpected return type" do
@@ -1128,6 +1146,25 @@ describe Addressable::URI, " when parsed from " +
1128
1146
  end
1129
1147
  end
1130
1148
 
1149
+ describe Addressable::URI, " when parsed from " +
1150
+ "'http://example.com:%38%30/'" do
1151
+ before do
1152
+ @uri = Addressable::URI.parse("http://example.com:%38%30/")
1153
+ end
1154
+
1155
+ it "should have the correct port" do
1156
+ @uri.port.should == 80
1157
+ end
1158
+
1159
+ it "should not be considered to be in normal form" do
1160
+ @uri.normalize.should_not be_eql(@uri)
1161
+ end
1162
+
1163
+ it "should normalize to 'http://example.com/'" do
1164
+ @uri.normalize.should === "http://example.com/"
1165
+ end
1166
+ end
1167
+
1131
1168
  describe Addressable::URI, " when parsed from " +
1132
1169
  "'http://example.com/path/to/resource/'" do
1133
1170
  before do
@@ -1788,6 +1825,11 @@ describe Addressable::URI, " when parsed from " +
1788
1825
  @uri.scheme.should == "ftp"
1789
1826
  @uri.to_s.should ==
1790
1827
  "ftp://user:pass@example.com/path/to/resource?query=x#fragment"
1828
+ @uri.scheme = "bogus!"
1829
+ @uri.scheme.should == "bogus!"
1830
+ @uri.normalized_scheme.should == "bogus%21"
1831
+ @uri.normalize.to_s.should ==
1832
+ "bogus%21://user:pass@example.com/path/to/resource?query=x#fragment"
1791
1833
  end
1792
1834
 
1793
1835
  it "should have the correct authority segment after assignment" do
@@ -1862,6 +1904,10 @@ describe Addressable::URI, " when parsed from " +
1862
1904
  @uri.query.should == "newquery=x"
1863
1905
  @uri.to_s.should ==
1864
1906
  "http://user:pass@example.com/path/to/resource?newquery=x#fragment"
1907
+ @uri.query = nil
1908
+ @uri.query.should == nil
1909
+ @uri.to_s.should ==
1910
+ "http://user:pass@example.com/path/to/resource#fragment"
1865
1911
  end
1866
1912
 
1867
1913
  it "should have the correct query string after hash assignment" do
@@ -102,6 +102,9 @@
102
102
  vendor/gems/addressable
103
103
  </code>
104
104
  </p>
105
+ <p>
106
+ Addressable works in Ruby 1.8.x, 1.9.x, and JRuby.
107
+ </p>
105
108
  </div>
106
109
  </body>
107
110
  </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-15 00:00:00 -05:00
12
+ date: 2008-12-02 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements: []
96
96
 
97
97
  rubyforge_project: addressable
98
- rubygems_version: 1.3.0
98
+ rubygems_version: 1.3.1
99
99
  signing_key:
100
100
  specification_version: 2
101
101
  summary: URI Implementation