addressable 2.1.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +65 -61
- data/LICENSE +1 -1
- data/README +12 -2
- data/Rakefile +0 -32
- data/lib/addressable/template.rb +1 -1
- data/lib/addressable/uri.rb +186 -89
- data/lib/addressable/version.rb +3 -3
- data/spec/addressable/uri_spec.rb +204 -11
- data/tasks/gem.rake +16 -0
- data/tasks/rdoc.rake +0 -3
- data/tasks/rubyforge.rake +1 -1
- data/tasks/yard.rake +26 -0
- metadata +64 -17
data/CHANGELOG
CHANGED
@@ -1,88 +1,92 @@
|
|
1
|
+
=== Addressable 2.2.0
|
2
|
+
- added site methods
|
3
|
+
- improved documentation
|
4
|
+
|
1
5
|
=== Addressable 2.1.2
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
- added HTTP request URI methods
|
7
|
+
- better handling of Windows file paths
|
8
|
+
- validation_deferred boolean replaced with defer_validation block
|
9
|
+
- normalization of percent-encoded paths should now be correct
|
10
|
+
- fixed issue with constructing URIs with relative paths
|
11
|
+
- fixed warnings
|
8
12
|
|
9
13
|
=== Addressable 2.1.1
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
- more type checking changes
|
15
|
+
- fixed issue with unicode normalization
|
16
|
+
- added method to find template defaults
|
17
|
+
- symbolic keys are now allowed in template mappings
|
18
|
+
- numeric values and symbolic values are now allowed in template mappings
|
15
19
|
|
16
20
|
=== Addressable 2.1.0
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
- refactored URI template support out into its own class
|
22
|
+
- removed extract method due to being useless and unreliable
|
23
|
+
- removed Addressable::URI.expand_template
|
24
|
+
- removed Addressable::URI#extract_mapping
|
25
|
+
- added partial template expansion
|
26
|
+
- fixed minor bugs in the parse and heuristic_parse methods
|
27
|
+
- fixed incompatibility with Ruby 1.9.1
|
28
|
+
- fixed bottleneck in Addressable::URI#hash and Addressable::URI#to_s
|
29
|
+
- fixed unicode normalization exception
|
30
|
+
- updated query_values methods to better handle subscript notation
|
31
|
+
- worked around issue with freezing URIs
|
32
|
+
- improved specs
|
29
33
|
|
30
34
|
=== Addressable 2.0.2
|
31
|
-
|
32
|
-
|
35
|
+
- fixed issue with URI template expansion
|
36
|
+
- fixed issue with percent escaping characters 0-15
|
33
37
|
|
34
38
|
=== Addressable 2.0.1
|
35
|
-
|
36
|
-
|
39
|
+
- fixed issue with query string assignment
|
40
|
+
- fixed issue with improperly encoded components
|
37
41
|
|
38
42
|
=== Addressable 2.0.0
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
43
|
+
- the initialize method now takes an options hash as its only parameter
|
44
|
+
- added query_values method to URI class
|
45
|
+
- completely replaced IDNA implementation with pure Ruby
|
46
|
+
- renamed Addressable::ADDRESSABLE_VERSION to Addressable::VERSION
|
47
|
+
- completely reworked the Rakefile
|
48
|
+
- changed the behavior of the port method significantly
|
49
|
+
- Addressable::URI.encode_segment, Addressable::URI.unencode_segment renamed
|
50
|
+
- documentation is now in YARD format
|
51
|
+
- more rigorous type checking
|
52
|
+
- to_str method implemented, implicit conversion to Strings now allowed
|
53
|
+
- Addressable::URI#omit method added, Addressable::URI#merge method replaced
|
54
|
+
- updated URI Template code to match v 03 of the draft spec
|
55
|
+
- added a bunch of new specifications
|
52
56
|
|
53
57
|
=== Addressable 1.0.4
|
54
|
-
|
55
|
-
|
58
|
+
- switched to using RSpec's pending system for specs that rely on IDN
|
59
|
+
- fixed issue with creating URIs with paths that are not prefixed with '/'
|
56
60
|
|
57
61
|
=== Addressable 1.0.3
|
58
|
-
|
62
|
+
- implemented a hash method
|
59
63
|
|
60
64
|
=== Addressable 1.0.2
|
61
|
-
|
65
|
+
- fixed minor bug with the extract_mapping method
|
62
66
|
|
63
67
|
=== Addressable 1.0.1
|
64
|
-
|
68
|
+
- fixed minor bug with the extract_mapping method
|
65
69
|
|
66
70
|
=== Addressable 1.0.0
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
- heuristic parse method added
|
72
|
+
- parsing is slightly more strict
|
73
|
+
- replaced to_h with to_hash
|
74
|
+
- fixed routing methods
|
75
|
+
- improved specifications
|
76
|
+
- improved heckle rake task
|
77
|
+
- no surviving heckle mutations
|
74
78
|
|
75
79
|
=== Addressable 0.1.2
|
76
|
-
|
77
|
-
|
78
|
-
|
80
|
+
- improved normalization
|
81
|
+
- fixed bug in joining algorithm
|
82
|
+
- updated specifications
|
79
83
|
|
80
84
|
=== Addressable 0.1.1
|
81
|
-
|
82
|
-
|
85
|
+
- updated documentation
|
86
|
+
- added URI Template variable extraction
|
83
87
|
|
84
88
|
=== Addressable 0.1.0
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
+
- initial release
|
90
|
+
- implementation based on RFC 3986, 3987
|
91
|
+
- support for IRIs via libidn
|
92
|
+
- support for the URI Template draft spec
|
data/LICENSE
CHANGED
data/README
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
+
== About
|
2
|
+
|
3
|
+
Homepage:: Addressable[http://addressable.rubyforge.org/]
|
4
|
+
Authors:: Bob Aman (mailto:bob@sporkmonger.com)
|
5
|
+
Copyright:: Copyright 2010 Bob Aman
|
6
|
+
License:: MIT
|
7
|
+
|
1
8
|
Addressable is a replacement for the URI implementation that is part of
|
2
9
|
Ruby's standard library. It more closely conforms to the relevant RFCs and
|
3
10
|
adds support for IRIs and URI templates. Additionally, it provides extensive
|
4
11
|
support for URI templates.
|
5
12
|
|
6
|
-
|
7
|
-
|
13
|
+
== Classes
|
14
|
+
- {Addressable::URI}
|
15
|
+
- {Addressable::Template}
|
16
|
+
|
17
|
+
== Example usage
|
8
18
|
require "addressable/uri"
|
9
19
|
|
10
20
|
uri = Addressable::URI.parse("http://example.com/path/to/resource/")
|
data/Rakefile
CHANGED
@@ -27,38 +27,6 @@ Ruby's standard library. It more closely conforms to the relevant RFCs and
|
|
27
27
|
adds support for IRIs and URI templates.
|
28
28
|
TEXT
|
29
29
|
|
30
|
-
desc "generates .gemspec file"
|
31
|
-
task :gemspec do
|
32
|
-
spec = Gem::Specification.new do |p|
|
33
|
-
p.name = 'addressable'
|
34
|
-
p.version = PKG_VERSION
|
35
|
-
|
36
|
-
p.summary = PKG_SUMMARY
|
37
|
-
p.description = PKG_DESCRIPTION
|
38
|
-
|
39
|
-
p.author = 'Bob Aman'
|
40
|
-
p.email = 'bob@sporkmonger.com'
|
41
|
-
p.homepage = 'http://github.com/mislav/addressable'
|
42
|
-
p.rubyforge_project = nil
|
43
|
-
|
44
|
-
p.files = FileList['Rakefile', '{bin,lib,tasks,spec}/**/*', 'README*', 'LICENSE*', 'CHANGELOG*'] & `git ls-files`.split
|
45
|
-
|
46
|
-
p.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
47
|
-
|
48
|
-
p.has_rdoc = true
|
49
|
-
end
|
50
|
-
|
51
|
-
spec_string = spec.to_ruby
|
52
|
-
|
53
|
-
begin
|
54
|
-
Thread.new { eval("$SAFE = 3\n#{spec_string}", binding) }.join
|
55
|
-
rescue
|
56
|
-
abort "unsafe gemspec: #{$!}"
|
57
|
-
else
|
58
|
-
File.open("#{spec.name}.gemspec", 'w') { |file| file.write spec_string }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
30
|
PKG_FILES = FileList[
|
63
31
|
"lib/**/*", "spec/**/*", "vendor/**/*",
|
64
32
|
"tasks/**/*", "website/**/*",
|
data/lib/addressable/template.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding:utf-8
|
2
2
|
#--
|
3
|
-
# Addressable, Copyright (c) 2006-
|
3
|
+
# Addressable, Copyright (c) 2006-2010 Bob Aman
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
# a copy of this software and associated documentation files (the
|
data/lib/addressable/uri.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding:utf-8
|
2
2
|
#--
|
3
|
-
# Addressable, Copyright (c) 2006-
|
3
|
+
# Addressable, Copyright (c) 2006-2010 Bob Aman
|
4
4
|
#
|
5
5
|
# Permission is hereby granted, free of charge, to any person obtaining
|
6
6
|
# a copy of this software and associated documentation files (the
|
@@ -58,9 +58,9 @@ module Addressable
|
|
58
58
|
# Returns a URI object based on the parsed string.
|
59
59
|
#
|
60
60
|
# @param [String, Addressable::URI, #to_str] uri
|
61
|
-
# The URI string to parse.
|
62
|
-
#
|
63
|
-
#
|
61
|
+
# The URI string to parse.
|
62
|
+
# No parsing is performed if the object is already an
|
63
|
+
# <code>Addressable::URI</code>.
|
64
64
|
#
|
65
65
|
# @return [Addressable::URI] The parsed URI.
|
66
66
|
def self.parse(uri)
|
@@ -130,11 +130,11 @@ module Addressable
|
|
130
130
|
#
|
131
131
|
# @param [String, Addressable::URI, #to_str] uri
|
132
132
|
# The URI string to parse.
|
133
|
-
#
|
134
|
-
#
|
133
|
+
# No parsing is performed if the object is already an
|
134
|
+
# <code>Addressable::URI</code>.
|
135
135
|
# @param [Hash] hints
|
136
|
-
# A <
|
137
|
-
#
|
136
|
+
# A <code>Hash</code> of hints to the heuristic parser.
|
137
|
+
# Defaults to <code>{:scheme => "http"}</code>.
|
138
138
|
#
|
139
139
|
# @return [Addressable::URI] The parsed URI.
|
140
140
|
def self.heuristic_parse(uri, hints={})
|
@@ -183,13 +183,13 @@ module Addressable
|
|
183
183
|
# Converts a path to a file scheme URI. If the path supplied is
|
184
184
|
# relative, it will be returned as a relative URI. If the path supplied
|
185
185
|
# is actually a non-file URI, it will parse the URI as if it had been
|
186
|
-
# parsed with <
|
186
|
+
# parsed with <code>Addressable::URI.parse</code>. Handles all of the
|
187
187
|
# various Microsoft-specific formats for specifying paths.
|
188
188
|
#
|
189
189
|
# @param [String, Addressable::URI, #to_str] path
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
190
|
+
# Typically a <code>String</code> path to a file or directory, but
|
191
|
+
# will return a sensible return value if an absolute URI is supplied
|
192
|
+
# instead.
|
193
193
|
#
|
194
194
|
# @return [Addressable::URI]
|
195
195
|
# The parsed file scheme URI or the original URI if some other URI
|
@@ -279,17 +279,17 @@ module Addressable
|
|
279
279
|
# @param [String, #to_str] component The URI component to encode.
|
280
280
|
#
|
281
281
|
# @param [String, Regexp] character_class
|
282
|
-
#
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
# href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>.
|
282
|
+
# The characters which are not percent encoded. If a <code>String</code>
|
283
|
+
# is passed, the <code>String</code> must be formatted as a regular
|
284
|
+
# expression character class. (Do not include the surrounding square
|
285
|
+
# brackets.) For example, <code>"b-zB-Z0-9"</code> would cause
|
286
|
+
# everything but the letters 'b' through 'z' and the numbers '0' through
|
287
|
+
# '9' to be percent encoded. If a <code>Regexp</code> is passed, the
|
288
|
+
# value <code>/[^b-zB-Z0-9]/</code> would have the same effect. A set of
|
289
|
+
# useful <code>String</code> values may be found in the
|
290
|
+
# <code>Addressable::URI::CharacterClasses</code> module. The default
|
291
|
+
# value is the reserved plus unreserved character classes specified in
|
292
|
+
# <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>.
|
293
293
|
#
|
294
294
|
# @return [String] The encoded component.
|
295
295
|
#
|
@@ -334,21 +334,21 @@ module Addressable
|
|
334
334
|
##
|
335
335
|
# Unencodes any percent encoded characters within a URI component.
|
336
336
|
# This method may be used for unencoding either components or full URIs,
|
337
|
-
# however, it is recommended to use the <
|
338
|
-
# when unencoding components.
|
337
|
+
# however, it is recommended to use the <code>unencode_component</code>
|
338
|
+
# alias when unencoding components.
|
339
339
|
#
|
340
340
|
# @param [String, Addressable::URI, #to_str] uri
|
341
341
|
# The URI or component to unencode.
|
342
342
|
#
|
343
343
|
# @param [Class] returning
|
344
344
|
# The type of object to return.
|
345
|
-
#
|
346
|
-
#
|
347
|
-
# <
|
345
|
+
# This value may only be set to <code>String</code> or
|
346
|
+
# <code>Addressable::URI</code>. All other values are invalid. Defaults
|
347
|
+
# to <code>String</code>.
|
348
348
|
#
|
349
349
|
# @return [String, Addressable::URI]
|
350
350
|
# The unencoded component or URI.
|
351
|
-
#
|
351
|
+
# The return type is determined by the <code>returning</code> parameter.
|
352
352
|
def self.unencode(uri, returning=String)
|
353
353
|
return nil if uri.nil?
|
354
354
|
if !uri.respond_to?(:to_str)
|
@@ -383,17 +383,17 @@ module Addressable
|
|
383
383
|
# @param [String, #to_str] component The URI component to encode.
|
384
384
|
#
|
385
385
|
# @param [String, Regexp] character_class
|
386
|
-
#
|
387
|
-
#
|
388
|
-
#
|
389
|
-
#
|
390
|
-
#
|
391
|
-
#
|
392
|
-
#
|
393
|
-
#
|
394
|
-
#
|
395
|
-
#
|
396
|
-
# href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>.
|
386
|
+
# The characters which are not percent encoded. If a <code>String</code>
|
387
|
+
# is passed, the <code>String</code> must be formatted as a regular
|
388
|
+
# expression character class. (Do not include the surrounding square
|
389
|
+
# brackets.) For example, <code>"b-zB-Z0-9"</code> would cause
|
390
|
+
# everything but the letters 'b' through 'z' and the numbers '0' through
|
391
|
+
# '9' to be percent encoded. If a <code>Regexp</code> is passed, the
|
392
|
+
# value <code>/[^b-zB-Z0-9]/</code> would have the same effect. A set of
|
393
|
+
# useful <code>String</code> values may be found in the
|
394
|
+
# <code>Addressable::URI::CharacterClasses</code> module. The default
|
395
|
+
# value is the reserved plus unreserved character classes specified in
|
396
|
+
# <a href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>.
|
397
397
|
#
|
398
398
|
# @return [String] The normalized component.
|
399
399
|
#
|
@@ -449,13 +449,13 @@ module Addressable
|
|
449
449
|
#
|
450
450
|
# @param [Class] returning
|
451
451
|
# The type of object to return.
|
452
|
-
#
|
453
|
-
#
|
454
|
-
# <
|
452
|
+
# This value may only be set to <code>String</code> or
|
453
|
+
# <code>Addressable::URI</code>. All other values are invalid. Defaults
|
454
|
+
# to <code>String</code>.
|
455
455
|
#
|
456
456
|
# @return [String, Addressable::URI]
|
457
457
|
# The encoded URI.
|
458
|
-
#
|
458
|
+
# The return type is determined by the <code>returning</code> parameter.
|
459
459
|
def self.encode(uri, returning=String)
|
460
460
|
return nil if uri.nil?
|
461
461
|
if !uri.respond_to?(:to_str)
|
@@ -499,13 +499,13 @@ module Addressable
|
|
499
499
|
#
|
500
500
|
# @param [Class] returning
|
501
501
|
# The type of object to return.
|
502
|
-
#
|
503
|
-
#
|
504
|
-
# <
|
502
|
+
# This value may only be set to <code>String</code> or
|
503
|
+
# <code>Addressable::URI</code>. All other values are invalid. Defaults
|
504
|
+
# to <code>String</code>.
|
505
505
|
#
|
506
506
|
# @return [String, Addressable::URI]
|
507
|
-
# The encoded URI.
|
508
|
-
#
|
507
|
+
# The encoded URI.
|
508
|
+
# The return type is determined by the <code>returning</code> parameter.
|
509
509
|
def self.normalized_encode(uri, returning=String)
|
510
510
|
if !uri.respond_to?(:to_str)
|
511
511
|
raise TypeError, "Can't convert #{uri.class} into String."
|
@@ -649,13 +649,19 @@ module Addressable
|
|
649
649
|
|
650
650
|
if new_scheme && !new_scheme.respond_to?(:to_str)
|
651
651
|
raise TypeError, "Can't convert #{new_scheme.class} into String."
|
652
|
+
elsif new_scheme
|
653
|
+
new_scheme = new_scheme.to_str
|
654
|
+
end
|
655
|
+
if new_scheme && new_scheme !~ /[a-z][a-z0-9\.\+\-]*/i
|
656
|
+
raise InvalidURIError, "Invalid scheme format."
|
652
657
|
end
|
653
|
-
@scheme = new_scheme
|
658
|
+
@scheme = new_scheme
|
654
659
|
@scheme = nil if @scheme.to_s.strip == ""
|
655
660
|
|
656
661
|
# Reset dependant values
|
657
662
|
@normalized_scheme = nil
|
658
663
|
@uri_string = nil
|
664
|
+
@hash = nil
|
659
665
|
|
660
666
|
# Ensure we haven't created an invalid URI
|
661
667
|
validate()
|
@@ -716,6 +722,7 @@ module Addressable
|
|
716
722
|
@authority = nil
|
717
723
|
@normalized_user = nil
|
718
724
|
@uri_string = nil
|
725
|
+
@hash = nil
|
719
726
|
|
720
727
|
# Ensure we haven't created an invalid URI
|
721
728
|
validate()
|
@@ -777,6 +784,7 @@ module Addressable
|
|
777
784
|
@authority = nil
|
778
785
|
@normalized_password = nil
|
779
786
|
@uri_string = nil
|
787
|
+
@hash = nil
|
780
788
|
|
781
789
|
# Ensure we haven't created an invalid URI
|
782
790
|
validate()
|
@@ -846,6 +854,7 @@ module Addressable
|
|
846
854
|
# Reset dependant values
|
847
855
|
@authority = nil
|
848
856
|
@uri_string = nil
|
857
|
+
@hash = nil
|
849
858
|
|
850
859
|
# Ensure we haven't created an invalid URI
|
851
860
|
validate()
|
@@ -901,6 +910,7 @@ module Addressable
|
|
901
910
|
@authority = nil
|
902
911
|
@normalized_host = nil
|
903
912
|
@uri_string = nil
|
913
|
+
@hash = nil
|
904
914
|
|
905
915
|
# Ensure we haven't created an invalid URI
|
906
916
|
validate()
|
@@ -986,6 +996,7 @@ module Addressable
|
|
986
996
|
@userinfo = nil
|
987
997
|
@normalized_userinfo = nil
|
988
998
|
@uri_string = nil
|
999
|
+
@hash = nil
|
989
1000
|
|
990
1001
|
# Ensure we haven't created an invalid URI
|
991
1002
|
validate()
|
@@ -993,7 +1004,7 @@ module Addressable
|
|
993
1004
|
|
994
1005
|
# Returns an array of known ip-based schemes. These schemes typically
|
995
1006
|
# use a similar URI form:
|
996
|
-
#
|
1007
|
+
# <code>//<user>:<password>@<host>:<port>/<url-path></code>
|
997
1008
|
def self.ip_based_schemes
|
998
1009
|
return self.port_mapping.keys
|
999
1010
|
end
|
@@ -1067,6 +1078,7 @@ module Addressable
|
|
1067
1078
|
@inferred_port = nil
|
1068
1079
|
@normalized_port = nil
|
1069
1080
|
@uri_string = nil
|
1081
|
+
@hash = nil
|
1070
1082
|
|
1071
1083
|
# Ensure we haven't created an invalid URI
|
1072
1084
|
validate()
|
@@ -1092,6 +1104,76 @@ module Addressable
|
|
1092
1104
|
end)
|
1093
1105
|
end
|
1094
1106
|
|
1107
|
+
##
|
1108
|
+
# The combination of components that represent a site.
|
1109
|
+
# Combines the scheme, user, password, host, and port components.
|
1110
|
+
# Primarily useful for HTTP and HTTPS.
|
1111
|
+
#
|
1112
|
+
# For example, <code>"http://example.com/path?query"</code> would have a
|
1113
|
+
# <code>site</code> value of <code>"http://example.com"</code>.
|
1114
|
+
#
|
1115
|
+
# @return [String] The components that identify a site.
|
1116
|
+
def site
|
1117
|
+
@site ||= (begin
|
1118
|
+
if self.scheme || self.authority
|
1119
|
+
site_string = ""
|
1120
|
+
site_string << "#{self.scheme}:" if self.scheme != nil
|
1121
|
+
site_string << "//#{self.authority}" if self.authority != nil
|
1122
|
+
site_string
|
1123
|
+
else
|
1124
|
+
nil
|
1125
|
+
end
|
1126
|
+
end)
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
##
|
1130
|
+
# The normalized combination of components that represent a site.
|
1131
|
+
# Combines the scheme, user, password, host, and port components.
|
1132
|
+
# Primarily useful for HTTP and HTTPS.
|
1133
|
+
#
|
1134
|
+
# For example, <code>"http://example.com/path?query"</code> would have a
|
1135
|
+
# <code>site</code> value of <code>"http://example.com"</code>.
|
1136
|
+
#
|
1137
|
+
# @return [String] The normalized components that identify a site.
|
1138
|
+
def normalized_site
|
1139
|
+
@site ||= (begin
|
1140
|
+
if self.normalized_scheme || self.normalized_authority
|
1141
|
+
site_string = ""
|
1142
|
+
if self.normalized_scheme != nil
|
1143
|
+
site_string << "#{self.normalized_scheme}:"
|
1144
|
+
end
|
1145
|
+
if self.normalized_authority != nil
|
1146
|
+
site_string << "//#{self.normalized_authority}"
|
1147
|
+
end
|
1148
|
+
site_string
|
1149
|
+
else
|
1150
|
+
nil
|
1151
|
+
end
|
1152
|
+
end)
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
##
|
1156
|
+
# Sets the site value for this URI.
|
1157
|
+
#
|
1158
|
+
# @param [String, #to_str] new_site The new site value.
|
1159
|
+
def site=(new_site)
|
1160
|
+
if new_site
|
1161
|
+
if !new_site.respond_to?(:to_str)
|
1162
|
+
raise TypeError, "Can't convert #{new_site.class} into String."
|
1163
|
+
end
|
1164
|
+
new_site = new_site.to_str
|
1165
|
+
# These two regular expressions derived from the primary parsing
|
1166
|
+
# expression
|
1167
|
+
self.scheme = new_site[/^(?:([^:\/?#]+):)?(?:\/\/(?:[^\/?#]*))?$/, 1]
|
1168
|
+
self.authority = new_site[
|
1169
|
+
/^(?:(?:[^:\/?#]+):)?(?:\/\/([^\/?#]*))?$/, 1
|
1170
|
+
]
|
1171
|
+
else
|
1172
|
+
self.scheme = nil
|
1173
|
+
self.authority = nil
|
1174
|
+
end
|
1175
|
+
end
|
1176
|
+
|
1095
1177
|
##
|
1096
1178
|
# The path component for this URI.
|
1097
1179
|
#
|
@@ -1148,6 +1230,7 @@ module Addressable
|
|
1148
1230
|
# Reset dependant values
|
1149
1231
|
@normalized_path = nil
|
1150
1232
|
@uri_string = nil
|
1233
|
+
@hash = nil
|
1151
1234
|
end
|
1152
1235
|
|
1153
1236
|
##
|
@@ -1210,15 +1293,16 @@ module Addressable
|
|
1210
1293
|
# Reset dependant values
|
1211
1294
|
@normalized_query = nil
|
1212
1295
|
@uri_string = nil
|
1296
|
+
@hash = nil
|
1213
1297
|
end
|
1214
1298
|
|
1215
1299
|
##
|
1216
1300
|
# Converts the query component to a Hash value.
|
1217
1301
|
#
|
1218
1302
|
# @option [Symbol] notation
|
1219
|
-
# May be one of <
|
1220
|
-
# The <
|
1221
|
-
# value is <
|
1303
|
+
# May be one of <code>:flat</code>, <code>:dot</code>, or
|
1304
|
+
# <code>:subscript</code>. The <code>:dot</code> notation is not
|
1305
|
+
# supported for assignment. Default value is <code>:subscript</code>.
|
1222
1306
|
#
|
1223
1307
|
# @return [Hash] The query string parsed as a Hash object.
|
1224
1308
|
#
|
@@ -1266,8 +1350,8 @@ module Addressable
|
|
1266
1350
|
end
|
1267
1351
|
return nil if self.query == nil
|
1268
1352
|
return ((self.query.split("&").map do |pair|
|
1269
|
-
pair.split("=")
|
1270
|
-
end).inject({}) do |accumulator, (key, value)|
|
1353
|
+
pair.split("=", -1) if pair && pair != ""
|
1354
|
+
end).compact.inject({}) do |accumulator, (key, value)|
|
1271
1355
|
value = true if value.nil?
|
1272
1356
|
key = self.class.unencode_component(key)
|
1273
1357
|
if value != true
|
@@ -1309,15 +1393,25 @@ module Addressable
|
|
1309
1393
|
##
|
1310
1394
|
# Sets the query component for this URI from a Hash object.
|
1311
1395
|
# This method produces a query string using the :subscript notation.
|
1396
|
+
# An empty Hash will result in a nil query.
|
1312
1397
|
#
|
1313
1398
|
# @param [Hash, #to_hash] new_query_values The new query values.
|
1314
1399
|
def query_values=(new_query_values)
|
1315
1400
|
# Check for frozenness
|
1316
1401
|
raise TypeError, "Can't modify frozen URI." if self.frozen?
|
1402
|
+
if new_query_values == nil
|
1403
|
+
self.query = nil
|
1404
|
+
return nil
|
1405
|
+
end
|
1317
1406
|
if !new_query_values.respond_to?(:to_hash)
|
1318
1407
|
raise TypeError, "Can't convert #{new_query_values.class} into Hash."
|
1319
1408
|
end
|
1320
1409
|
new_query_values = new_query_values.to_hash
|
1410
|
+
new_query_values = new_query_values.map do |key, value|
|
1411
|
+
key = key.to_s if key.kind_of?(Symbol)
|
1412
|
+
[key, value]
|
1413
|
+
end
|
1414
|
+
new_query_values.sort! # Useful default for OAuth and caching
|
1321
1415
|
|
1322
1416
|
# Algorithm shamelessly stolen from Julien Genestoux, slightly modified
|
1323
1417
|
buffer = ""
|
@@ -1351,11 +1445,7 @@ module Addressable
|
|
1351
1445
|
end
|
1352
1446
|
end
|
1353
1447
|
end
|
1354
|
-
|
1355
|
-
|
1356
|
-
# Reset dependant values
|
1357
|
-
@normalized_query = nil
|
1358
|
-
@uri_string = nil
|
1448
|
+
self.query = buffer.chop
|
1359
1449
|
end
|
1360
1450
|
|
1361
1451
|
##
|
@@ -1393,6 +1483,7 @@ module Addressable
|
|
1393
1483
|
|
1394
1484
|
# Reset dependant values
|
1395
1485
|
@uri_string = nil
|
1486
|
+
@hash = nil
|
1396
1487
|
end
|
1397
1488
|
|
1398
1489
|
##
|
@@ -1436,6 +1527,7 @@ module Addressable
|
|
1436
1527
|
# Reset dependant values
|
1437
1528
|
@normalized_fragment = nil
|
1438
1529
|
@uri_string = nil
|
1530
|
+
@hash = nil
|
1439
1531
|
|
1440
1532
|
# Ensure we haven't created an invalid URI
|
1441
1533
|
validate()
|
@@ -1445,8 +1537,8 @@ module Addressable
|
|
1445
1537
|
# Determines if the scheme indicates an IP-based protocol.
|
1446
1538
|
#
|
1447
1539
|
# @return [TrueClass, FalseClass]
|
1448
|
-
#
|
1449
|
-
#
|
1540
|
+
# <code>true</code> if the scheme indicates an IP-based protocol.
|
1541
|
+
# <code>false</code> otherwise.
|
1450
1542
|
def ip_based?
|
1451
1543
|
if self.scheme
|
1452
1544
|
return self.class.ip_based_schemes.include?(
|
@@ -1459,7 +1551,8 @@ module Addressable
|
|
1459
1551
|
# Determines if the URI is relative.
|
1460
1552
|
#
|
1461
1553
|
# @return [TrueClass, FalseClass]
|
1462
|
-
#
|
1554
|
+
# <code>true</code> if the URI is relative. <code>false</code>
|
1555
|
+
# otherwise.
|
1463
1556
|
def relative?
|
1464
1557
|
return self.scheme.nil?
|
1465
1558
|
end
|
@@ -1468,7 +1561,8 @@ module Addressable
|
|
1468
1561
|
# Determines if the URI is absolute.
|
1469
1562
|
#
|
1470
1563
|
# @return [TrueClass, FalseClass]
|
1471
|
-
#
|
1564
|
+
# <code>true</code> if the URI is absolute. <code>false</code>
|
1565
|
+
# otherwise.
|
1472
1566
|
def absolute?
|
1473
1567
|
return !relative?
|
1474
1568
|
end
|
@@ -1575,7 +1669,7 @@ module Addressable
|
|
1575
1669
|
alias_method :+, :join
|
1576
1670
|
|
1577
1671
|
##
|
1578
|
-
# Destructive form of <
|
1672
|
+
# Destructive form of <code>join</code>.
|
1579
1673
|
#
|
1580
1674
|
# @param [String, Addressable::URI, #to_str] The URI to join with.
|
1581
1675
|
#
|
@@ -1587,10 +1681,10 @@ module Addressable
|
|
1587
1681
|
end
|
1588
1682
|
|
1589
1683
|
##
|
1590
|
-
# Merges a URI with a <
|
1591
|
-
# This method has different behavior from <
|
1592
|
-
# present in the <
|
1593
|
-
# components. The path component is not treated specially.
|
1684
|
+
# Merges a URI with a <code>Hash</code> of components.
|
1685
|
+
# This method has different behavior from <code>join</code>. Any
|
1686
|
+
# components present in the <code>hash</code> parameter will override the
|
1687
|
+
# original components. The path component is not treated specially.
|
1594
1688
|
#
|
1595
1689
|
# @param [Hash, Addressable::URI, #to_hash] The components to merge with.
|
1596
1690
|
#
|
@@ -1655,7 +1749,7 @@ module Addressable
|
|
1655
1749
|
end
|
1656
1750
|
|
1657
1751
|
##
|
1658
|
-
# Destructive form of <
|
1752
|
+
# Destructive form of <code>merge</code>.
|
1659
1753
|
#
|
1660
1754
|
# @param [Hash, Addressable::URI, #to_hash] The components to merge with.
|
1661
1755
|
#
|
@@ -1669,7 +1763,7 @@ module Addressable
|
|
1669
1763
|
##
|
1670
1764
|
# Returns the shortest normalized relative form of this URI that uses the
|
1671
1765
|
# supplied URI as a base for resolution. Returns an absolute URI if
|
1672
|
-
# necessary. This is effectively the opposite of <
|
1766
|
+
# necessary. This is effectively the opposite of <code>route_to</code>.
|
1673
1767
|
#
|
1674
1768
|
# @param [String, Addressable::URI, #to_str] uri The URI to route from.
|
1675
1769
|
#
|
@@ -1727,7 +1821,7 @@ module Addressable
|
|
1727
1821
|
##
|
1728
1822
|
# Returns the shortest normalized relative form of the supplied URI that
|
1729
1823
|
# uses this URI as a base for resolution. Returns an absolute URI if
|
1730
|
-
# necessary. This is effectively the opposite of <
|
1824
|
+
# necessary. This is effectively the opposite of <code>route_from</code>.
|
1731
1825
|
#
|
1732
1826
|
# @param [String, Addressable::URI, #to_str] uri The URI to route to.
|
1733
1827
|
#
|
@@ -1791,14 +1885,15 @@ module Addressable
|
|
1791
1885
|
end
|
1792
1886
|
|
1793
1887
|
##
|
1794
|
-
# Returns <
|
1888
|
+
# Returns <code>true</code> if the URI objects are equal. This method
|
1795
1889
|
# normalizes both URIs before doing the comparison, and allows comparison
|
1796
|
-
# against <
|
1890
|
+
# against <code>Strings</code>.
|
1797
1891
|
#
|
1798
1892
|
# @param [Object] uri The URI to compare.
|
1799
1893
|
#
|
1800
1894
|
# @return [TrueClass, FalseClass]
|
1801
|
-
# <
|
1895
|
+
# <code>true</code> if the URIs are equivalent, <code>false</code>
|
1896
|
+
# otherwise.
|
1802
1897
|
def ===(uri)
|
1803
1898
|
if uri.respond_to?(:normalize)
|
1804
1899
|
uri_string = uri.normalize.to_s
|
@@ -1813,26 +1908,28 @@ module Addressable
|
|
1813
1908
|
end
|
1814
1909
|
|
1815
1910
|
##
|
1816
|
-
# Returns <
|
1911
|
+
# Returns <code>true</code> if the URI objects are equal. This method
|
1817
1912
|
# normalizes both URIs before doing the comparison.
|
1818
1913
|
#
|
1819
1914
|
# @param [Object] uri The URI to compare.
|
1820
1915
|
#
|
1821
1916
|
# @return [TrueClass, FalseClass]
|
1822
|
-
# <
|
1917
|
+
# <code>true</code> if the URIs are equivalent, <code>false</code>
|
1918
|
+
# otherwise.
|
1823
1919
|
def ==(uri)
|
1824
1920
|
return false unless uri.kind_of?(self.class)
|
1825
1921
|
return self.normalize.to_s == uri.normalize.to_s
|
1826
1922
|
end
|
1827
1923
|
|
1828
1924
|
##
|
1829
|
-
# Returns <
|
1925
|
+
# Returns <code>true</code> if the URI objects are equal. This method
|
1830
1926
|
# does NOT normalize either URI before doing the comparison.
|
1831
1927
|
#
|
1832
1928
|
# @param [Object] uri The URI to compare.
|
1833
1929
|
#
|
1834
1930
|
# @return [TrueClass, FalseClass]
|
1835
|
-
# <
|
1931
|
+
# <code>true</code> if the URIs are equivalent, <code>false</code>
|
1932
|
+
# otherwise.
|
1836
1933
|
def eql?(uri)
|
1837
1934
|
return false unless uri.kind_of?(self.class)
|
1838
1935
|
return self.to_s == uri.to_s
|
@@ -1882,7 +1979,7 @@ module Addressable
|
|
1882
1979
|
# Determines if the URI is frozen.
|
1883
1980
|
#
|
1884
1981
|
# @return [TrueClass, FalseClass]
|
1885
|
-
#
|
1982
|
+
# <code>true</code> if the URI is frozen, <code>false</code> otherwise.
|
1886
1983
|
def frozen?
|
1887
1984
|
self.to_s.frozen?
|
1888
1985
|
end
|
@@ -1931,9 +2028,9 @@ module Addressable
|
|
1931
2028
|
end
|
1932
2029
|
|
1933
2030
|
##
|
1934
|
-
# Converts the URI to a <
|
2031
|
+
# Converts the URI to a <code>String</code>.
|
1935
2032
|
#
|
1936
|
-
# @return [String] The URI's <
|
2033
|
+
# @return [String] The URI's <code>String</code> representation.
|
1937
2034
|
def to_s
|
1938
2035
|
@uri_string ||= (begin
|
1939
2036
|
uri_string = ""
|
@@ -1950,13 +2047,13 @@ module Addressable
|
|
1950
2047
|
end
|
1951
2048
|
|
1952
2049
|
##
|
1953
|
-
# URI's are glorified <
|
2050
|
+
# URI's are glorified <code>Strings</code>. Allow implicit conversion.
|
1954
2051
|
alias_method :to_str, :to_s
|
1955
2052
|
|
1956
2053
|
##
|
1957
2054
|
# Returns a Hash of the URI components.
|
1958
2055
|
#
|
1959
|
-
# @return [Hash] The URI as a <
|
2056
|
+
# @return [Hash] The URI as a <code>Hash</code> of components.
|
1960
2057
|
def to_hash
|
1961
2058
|
return {
|
1962
2059
|
:scheme => self.scheme,
|
@@ -1971,9 +2068,9 @@ module Addressable
|
|
1971
2068
|
end
|
1972
2069
|
|
1973
2070
|
##
|
1974
|
-
# Returns a <
|
2071
|
+
# Returns a <code>String</code> representation of the URI object's state.
|
1975
2072
|
#
|
1976
|
-
# @return [String] The URI object's state, as a <
|
2073
|
+
# @return [String] The URI object's state, as a <code>String</code>.
|
1977
2074
|
def inspect
|
1978
2075
|
sprintf("#<%s:%#0x URI:%s>", self.class.to_s, self.object_id, self.to_s)
|
1979
2076
|
end
|
@@ -2055,9 +2152,9 @@ module Addressable
|
|
2055
2152
|
# Replaces the internal state of self with the specified URI's state.
|
2056
2153
|
# Used in destructive operations to avoid massive code repetition.
|
2057
2154
|
#
|
2058
|
-
# @param [Addressable::URI] uri The URI to replace <
|
2155
|
+
# @param [Addressable::URI] uri The URI to replace <code>self</code> with.
|
2059
2156
|
#
|
2060
|
-
# @return [Addressable::URI] <
|
2157
|
+
# @return [Addressable::URI] <code>self</code>.
|
2061
2158
|
def replace_self(uri)
|
2062
2159
|
# Reset dependant values
|
2063
2160
|
instance_variables.each do |var|
|