addressable 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +9 -0
- data/coverage/index.html +5 -5
- data/coverage/lib-addressable-uri_rb.html +1116 -1103
- data/coverage/lib-addressable-version_rb.html +33 -33
- data/doc/classes/Addressable/URI.html +1237 -1202
- data/doc/classes/Addressable/URI/IDNA.html +34 -34
- data/doc/created.rid +1 -1
- data/doc/files/CHANGELOG.html +12 -2
- data/doc/files/lib/addressable/uri_rb.html +1 -1
- data/doc/files/lib/addressable/version_rb.html +1 -1
- data/doc/fr_method_index.html +58 -57
- data/lib/addressable/uri.rb +90 -77
- data/lib/addressable/version.rb +3 -3
- data/rakefile +6 -15
- data/spec/addressable/uri_spec.rb +503 -23
- metadata +2 -2
@@ -89,8 +89,8 @@ returning nil if libidn can‘t be used.
|
|
89
89
|
<h3 class="section-bar">Methods</h3>
|
90
90
|
|
91
91
|
<div class="name-list">
|
92
|
-
<a href="#
|
93
|
-
<a href="#
|
92
|
+
<a href="#M000058">to_ascii</a>
|
93
|
+
<a href="#M000059">to_unicode</a>
|
94
94
|
</div>
|
95
95
|
</div>
|
96
96
|
|
@@ -112,11 +112,11 @@ returning nil if libidn can‘t be used.
|
|
112
112
|
<div id="methods">
|
113
113
|
<h3 class="section-bar">Public Class methods</h3>
|
114
114
|
|
115
|
-
<div id="method-
|
116
|
-
<a name="
|
115
|
+
<div id="method-M000058" class="method-detail">
|
116
|
+
<a name="M000058"></a>
|
117
117
|
|
118
118
|
<div class="method-heading">
|
119
|
-
<a href="#
|
119
|
+
<a href="#M000058" class="method-signature">
|
120
120
|
<span class="method-name">to_ascii</span><span class="method-args">(label)</span>
|
121
121
|
</a>
|
122
122
|
</div>
|
@@ -126,30 +126,30 @@ returning nil if libidn can‘t be used.
|
|
126
126
|
Returns the ascii representation of the label.
|
127
127
|
</p>
|
128
128
|
<p><a class="source-toggle" href="#"
|
129
|
-
onclick="toggleCode('
|
130
|
-
<div class="method-source-code" id="
|
129
|
+
onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
|
130
|
+
<div class="method-source-code" id="M000058-source">
|
131
131
|
<pre>
|
132
|
-
<span class="ruby-comment cmt"># File lib/addressable/uri.rb, line
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
132
|
+
<span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1114</span>
|
133
|
+
1114: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_ascii</span>(<span class="ruby-identifier">label</span>)
|
134
|
+
1115: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">label</span>.<span class="ruby-identifier">nil?</span>
|
135
|
+
1116: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">use_libidn?</span>
|
136
|
+
1117: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Idna</span>.<span class="ruby-identifier">toASCII</span>(<span class="ruby-identifier">label</span>)
|
137
|
+
1118: <span class="ruby-keyword kw">else</span>
|
138
|
+
1119: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>,
|
139
|
+
1120: <span class="ruby-value str">"There is no available pure-ruby implementation. "</span> <span class="ruby-operator">+</span>
|
140
|
+
1121: <span class="ruby-value str">"Install libidn bindings."</span>
|
141
|
+
1122: <span class="ruby-keyword kw">end</span>
|
142
|
+
1123: <span class="ruby-keyword kw">end</span>
|
143
143
|
</pre>
|
144
144
|
</div>
|
145
145
|
</div>
|
146
146
|
</div>
|
147
147
|
|
148
|
-
<div id="method-
|
149
|
-
<a name="
|
148
|
+
<div id="method-M000059" class="method-detail">
|
149
|
+
<a name="M000059"></a>
|
150
150
|
|
151
151
|
<div class="method-heading">
|
152
|
-
<a href="#
|
152
|
+
<a href="#M000059" class="method-signature">
|
153
153
|
<span class="method-name">to_unicode</span><span class="method-args">(label)</span>
|
154
154
|
</a>
|
155
155
|
</div>
|
@@ -159,20 +159,20 @@ Returns the ascii representation of the label.
|
|
159
159
|
Returns the unicode representation of the label.
|
160
160
|
</p>
|
161
161
|
<p><a class="source-toggle" href="#"
|
162
|
-
onclick="toggleCode('
|
163
|
-
<div class="method-source-code" id="
|
162
|
+
onclick="toggleCode('M000059-source');return false;">[Source]</a></p>
|
163
|
+
<div class="method-source-code" id="M000059-source">
|
164
164
|
<pre>
|
165
|
-
<span class="ruby-comment cmt"># File lib/addressable/uri.rb, line
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
165
|
+
<span class="ruby-comment cmt"># File lib/addressable/uri.rb, line 1126</span>
|
166
|
+
1126: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_unicode</span>(<span class="ruby-identifier">label</span>)
|
167
|
+
1127: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">label</span>.<span class="ruby-identifier">nil?</span>
|
168
|
+
1128: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">use_libidn?</span>
|
169
|
+
1129: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">IDN</span><span class="ruby-operator">::</span><span class="ruby-constant">Idna</span>.<span class="ruby-identifier">toUnicode</span>(<span class="ruby-identifier">label</span>)
|
170
|
+
1130: <span class="ruby-keyword kw">else</span>
|
171
|
+
1131: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NotImplementedError</span>,
|
172
|
+
1132: <span class="ruby-value str">"There is no available pure-ruby implementation. "</span> <span class="ruby-operator">+</span>
|
173
|
+
1133: <span class="ruby-value str">"Install libidn bindings."</span>
|
174
|
+
1134: <span class="ruby-keyword kw">end</span>
|
175
|
+
1135: <span class="ruby-keyword kw">end</span>
|
176
176
|
</pre>
|
177
177
|
</div>
|
178
178
|
</div>
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Sat Nov 03 22:20:27 -0400 2007
|
data/doc/files/CHANGELOG.html
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Sat Nov 03 19:31:11 -0400 2007</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -69,7 +69,17 @@
|
|
69
69
|
<div id="contextContent">
|
70
70
|
|
71
71
|
<div id="description">
|
72
|
-
<h3><a href="../classes/Addressable.html">Addressable</a> 0.
|
72
|
+
<h3><a href="../classes/Addressable.html">Addressable</a> 1.0.0</h3>
|
73
|
+
<pre>
|
74
|
+
* heuristic parse method added
|
75
|
+
* parsing is slightly more strict
|
76
|
+
* replaced to_h with to_hash
|
77
|
+
* fixed routing methods
|
78
|
+
* improved specifications
|
79
|
+
* improved heckle rake task
|
80
|
+
* no surviving heckle mutations
|
81
|
+
</pre>
|
82
|
+
<h3><a href="../classes/Addressable.html">Addressable</a> 0.1.2</h3>
|
73
83
|
<pre>
|
74
84
|
* improved normalization
|
75
85
|
* fixed bug in joining algorithm
|
data/doc/fr_method_index.html
CHANGED
@@ -20,64 +20,65 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
|
-
<a href="classes/Addressable/URI.html#
|
24
|
-
<a href="classes/Addressable/URI.html#
|
25
|
-
<a href="classes/Addressable/URI.html#
|
26
|
-
<a href="classes/Addressable/URI.html#
|
27
|
-
<a href="classes/Addressable/URI.html#
|
28
|
-
<a href="classes/Addressable/URI.html#
|
29
|
-
<a href="classes/Addressable/URI.html#
|
30
|
-
<a href="classes/Addressable/URI.html#
|
31
|
-
<a href="classes/Addressable/URI.html#
|
32
|
-
<a href="classes/Addressable/URI.html#
|
33
|
-
<a href="classes/Addressable/URI.html#
|
34
|
-
<a href="classes/Addressable/URI.html#
|
35
|
-
<a href="classes/Addressable/URI.html#
|
36
|
-
<a href="classes/Addressable/URI.html#
|
37
|
-
<a href="classes/Addressable/URI.html#
|
38
|
-
<a href="classes/Addressable/URI.html#
|
39
|
-
<a href="classes/Addressable/URI.html#
|
40
|
-
<a href="classes/Addressable/URI.html#
|
41
|
-
<a href="classes/Addressable/URI.html#
|
42
|
-
<a href="classes/Addressable/URI.html#
|
43
|
-
<a href="classes/Addressable/URI.html#M000021">host
|
44
|
-
<a href="classes/Addressable/URI.html#
|
45
|
-
<a href="classes/Addressable/URI.html#
|
46
|
-
<a href="classes/Addressable/URI.html#
|
47
|
-
<a href="classes/Addressable/URI.html#
|
48
|
-
<a href="classes/Addressable/URI.html#
|
49
|
-
<a href="classes/Addressable/URI.html#
|
50
|
-
<a href="classes/Addressable/URI.html#
|
51
|
-
<a href="classes/Addressable/URI.html#
|
52
|
-
<a href="classes/Addressable/URI.html#
|
53
|
-
<a href="classes/Addressable/URI.html#
|
54
|
-
<a href="classes/Addressable/URI.html#M000048">normalize
|
55
|
-
<a href="classes/Addressable/URI.html#
|
23
|
+
<a href="classes/Addressable/URI.html#M000041">+ (Addressable::URI)</a><br />
|
24
|
+
<a href="classes/Addressable/URI.html#M000052">== (Addressable::URI)</a><br />
|
25
|
+
<a href="classes/Addressable/URI.html#M000051">=== (Addressable::URI)</a><br />
|
26
|
+
<a href="classes/Addressable/URI.html#M000040">absolute? (Addressable::URI)</a><br />
|
27
|
+
<a href="classes/Addressable/URI.html#M000023">authority (Addressable::URI)</a><br />
|
28
|
+
<a href="classes/Addressable/URI.html#M000024">authority= (Addressable::URI)</a><br />
|
29
|
+
<a href="classes/Addressable/URI.html#M000032">basename (Addressable::URI)</a><br />
|
30
|
+
<a href="classes/Addressable/URI.html#M000003">convert_path (Addressable::URI)</a><br />
|
31
|
+
<a href="classes/Addressable/URI.html#M000050">display_uri (Addressable::URI)</a><br />
|
32
|
+
<a href="classes/Addressable/URI.html#M000054">dup (Addressable::URI)</a><br />
|
33
|
+
<a href="classes/Addressable/URI.html#M000009">encode (Addressable::URI)</a><br />
|
34
|
+
<a href="classes/Addressable/URI.html#M000007">encode_segment (Addressable::URI)</a><br />
|
35
|
+
<a href="classes/Addressable/URI.html#M000053">eql? (Addressable::URI)</a><br />
|
36
|
+
<a href="classes/Addressable/URI.html#M000004">expand_template (Addressable::URI)</a><br />
|
37
|
+
<a href="classes/Addressable/URI.html#M000033">extname (Addressable::URI)</a><br />
|
38
|
+
<a href="classes/Addressable/URI.html#M000011">extract (Addressable::URI)</a><br />
|
39
|
+
<a href="classes/Addressable/URI.html#M000005">extract_mapping (Addressable::URI)</a><br />
|
40
|
+
<a href="classes/Addressable/URI.html#M000036">fragment (Addressable::URI)</a><br />
|
41
|
+
<a href="classes/Addressable/URI.html#M000037">fragment= (Addressable::URI)</a><br />
|
42
|
+
<a href="classes/Addressable/URI.html#M000002">heuristic_parse (Addressable::URI)</a><br />
|
43
|
+
<a href="classes/Addressable/URI.html#M000021">host (Addressable::URI)</a><br />
|
44
|
+
<a href="classes/Addressable/URI.html#M000022">host= (Addressable::URI)</a><br />
|
45
|
+
<a href="classes/Addressable/URI.html#M000057">inspect (Addressable::URI)</a><br />
|
46
|
+
<a href="classes/Addressable/URI.html#M000038">ip_based? (Addressable::URI)</a><br />
|
47
|
+
<a href="classes/Addressable/URI.html#M000025">ip_based_schemes (Addressable::URI)</a><br />
|
48
|
+
<a href="classes/Addressable/URI.html#M000043">join (Addressable::URI)</a><br />
|
49
|
+
<a href="classes/Addressable/URI.html#M000006">join (Addressable::URI)</a><br />
|
50
|
+
<a href="classes/Addressable/URI.html#M000045">join! (Addressable::URI)</a><br />
|
51
|
+
<a href="classes/Addressable/URI.html#M000042">merge (Addressable::URI)</a><br />
|
52
|
+
<a href="classes/Addressable/URI.html#M000044">merge! (Addressable::URI)</a><br />
|
53
|
+
<a href="classes/Addressable/URI.html#M000012">new (Addressable::URI)</a><br />
|
54
|
+
<a href="classes/Addressable/URI.html#M000048">normalize (Addressable::URI)</a><br />
|
55
|
+
<a href="classes/Addressable/URI.html#M000049">normalize! (Addressable::URI)</a><br />
|
56
|
+
<a href="classes/Addressable/URI.html#M000010">normalized_encode (Addressable::URI)</a><br />
|
56
57
|
<a href="classes/Addressable/URI.html#M000001">parse (Addressable::URI)</a><br />
|
57
|
-
<a href="classes/Addressable/URI.html#
|
58
|
-
<a href="classes/Addressable/URI.html#
|
59
|
-
<a href="classes/Addressable/URI.html#
|
60
|
-
<a href="classes/Addressable/URI.html#
|
61
|
-
<a href="classes/Addressable/URI.html#
|
62
|
-
<a href="classes/Addressable/URI.html#
|
63
|
-
<a href="classes/Addressable/URI.html#
|
64
|
-
<a href="classes/Addressable/URI.html#
|
65
|
-
<a href="classes/Addressable/URI.html#
|
66
|
-
<a href="classes/Addressable/URI.html#
|
67
|
-
<a href="classes/Addressable/URI.html#
|
68
|
-
<a href="classes/Addressable/URI.html#
|
69
|
-
<a href="classes/Addressable/URI.html#
|
70
|
-
<a href="classes/Addressable/URI.html#
|
71
|
-
<a href="classes/Addressable/URI.html#
|
72
|
-
<a href="classes/Addressable/URI/IDNA.html#
|
73
|
-
<a href="classes/Addressable/URI.html#
|
74
|
-
<a href="classes/Addressable/URI.html#
|
75
|
-
<a href="classes/Addressable/URI/IDNA.html#
|
76
|
-
<a href="classes/Addressable/URI.html#
|
77
|
-
<a href="classes/Addressable/URI.html#
|
78
|
-
<a href="classes/Addressable/URI.html#
|
79
|
-
<a href="classes/Addressable/URI.html#
|
80
|
-
<a href="classes/Addressable/URI.html#
|
58
|
+
<a href="classes/Addressable/URI.html#M000017">password (Addressable::URI)</a><br />
|
59
|
+
<a href="classes/Addressable/URI.html#M000018">password= (Addressable::URI)</a><br />
|
60
|
+
<a href="classes/Addressable/URI.html#M000030">path (Addressable::URI)</a><br />
|
61
|
+
<a href="classes/Addressable/URI.html#M000031">path= (Addressable::URI)</a><br />
|
62
|
+
<a href="classes/Addressable/URI.html#M000027">port (Addressable::URI)</a><br />
|
63
|
+
<a href="classes/Addressable/URI.html#M000028">port= (Addressable::URI)</a><br />
|
64
|
+
<a href="classes/Addressable/URI.html#M000034">query (Addressable::URI)</a><br />
|
65
|
+
<a href="classes/Addressable/URI.html#M000035">query= (Addressable::URI)</a><br />
|
66
|
+
<a href="classes/Addressable/URI.html#M000039">relative? (Addressable::URI)</a><br />
|
67
|
+
<a href="classes/Addressable/URI.html#M000046">route_from (Addressable::URI)</a><br />
|
68
|
+
<a href="classes/Addressable/URI.html#M000047">route_to (Addressable::URI)</a><br />
|
69
|
+
<a href="classes/Addressable/URI.html#M000013">scheme (Addressable::URI)</a><br />
|
70
|
+
<a href="classes/Addressable/URI.html#M000014">scheme= (Addressable::URI)</a><br />
|
71
|
+
<a href="classes/Addressable/URI.html#M000026">scheme_mapping (Addressable::URI)</a><br />
|
72
|
+
<a href="classes/Addressable/URI.html#M000029">specified_port (Addressable::URI)</a><br />
|
73
|
+
<a href="classes/Addressable/URI/IDNA.html#M000058">to_ascii (Addressable::URI::IDNA)</a><br />
|
74
|
+
<a href="classes/Addressable/URI.html#M000056">to_hash (Addressable::URI)</a><br />
|
75
|
+
<a href="classes/Addressable/URI.html#M000055">to_s (Addressable::URI)</a><br />
|
76
|
+
<a href="classes/Addressable/URI/IDNA.html#M000059">to_unicode (Addressable::URI::IDNA)</a><br />
|
77
|
+
<a href="classes/Addressable/URI.html#M000008">unencode_segment (Addressable::URI)</a><br />
|
78
|
+
<a href="classes/Addressable/URI.html#M000015">user (Addressable::URI)</a><br />
|
79
|
+
<a href="classes/Addressable/URI.html#M000016">user= (Addressable::URI)</a><br />
|
80
|
+
<a href="classes/Addressable/URI.html#M000019">userinfo (Addressable::URI)</a><br />
|
81
|
+
<a href="classes/Addressable/URI.html#M000020">userinfo= (Addressable::URI)</a><br />
|
81
82
|
</div>
|
82
83
|
</div>
|
83
84
|
</body>
|
data/lib/addressable/uri.rb
CHANGED
@@ -93,31 +93,51 @@ module Addressable
|
|
93
93
|
host = authority.gsub(/^([^\[\]]*)@/, "").gsub(/:([^:@\[\]]*?)$/, "")
|
94
94
|
port = authority.scan(/:([^:@\[\]]*?)$/).flatten[0]
|
95
95
|
end
|
96
|
-
if port
|
96
|
+
if port == nil || port == ""
|
97
97
|
port = nil
|
98
98
|
end
|
99
99
|
|
100
|
-
# WARNING: Not standards-compliant, but follows the theme
|
101
|
-
# of Postel's law:
|
102
|
-
#
|
103
|
-
# Special exception for dealing with the retarded idea of the
|
104
|
-
# feed pseudo-protocol. Without this exception, the parser will read
|
105
|
-
# the URI as having a blank port number, instead of as having a second
|
106
|
-
# URI embedded within. This exception translates these broken URIs
|
107
|
-
# and instead treats the inner URI as opaque.
|
108
|
-
if scheme == "feed" && host == "http"
|
109
|
-
userinfo = nil
|
110
|
-
user = nil
|
111
|
-
password = nil
|
112
|
-
host = nil
|
113
|
-
port = nil
|
114
|
-
path = authority + path
|
115
|
-
end
|
116
|
-
|
117
100
|
return Addressable::URI.new(
|
118
101
|
scheme, user, password, host, port, path, query, fragment)
|
119
102
|
end
|
120
103
|
|
104
|
+
# Converts an input to a URI. The input does not have to be a valid
|
105
|
+
# URI -- the method will use heuristics to guess what URI was intended.
|
106
|
+
# This is not standards compliant, merely user-friendly.
|
107
|
+
def self.heuristic_parse(input, hints={})
|
108
|
+
input = input.dup
|
109
|
+
hints = {
|
110
|
+
:scheme => "http"
|
111
|
+
}.merge(hints)
|
112
|
+
case input
|
113
|
+
when /^http:\/+/
|
114
|
+
input.gsub!(/^http:\/+/, "http://")
|
115
|
+
when /^feed:\/+http:\/+/
|
116
|
+
input.gsub!(/^feed:\/+http:\/+/, "feed:http://")
|
117
|
+
when /^feed:\/+/
|
118
|
+
input.gsub!(/^feed:\/+/, "feed://")
|
119
|
+
when /^file:\/+/
|
120
|
+
input.gsub!(/^file:\/+/, "file:///")
|
121
|
+
end
|
122
|
+
parsed = self.parse(input)
|
123
|
+
if parsed.scheme =~ /^[^\/?#\.]+\.[^\/?#]+$/
|
124
|
+
parsed = self.parse(hints[:scheme] + "://" + input)
|
125
|
+
end
|
126
|
+
if parsed.authority == nil
|
127
|
+
if parsed.path =~ /^[^\/]+\./
|
128
|
+
new_host = parsed.path.scan(/^([^\/]+\.[^\/]*)/).flatten[0]
|
129
|
+
if new_host
|
130
|
+
new_path = parsed.path.gsub(
|
131
|
+
Regexp.new("^" + Regexp.escape(new_host)), "")
|
132
|
+
parsed.host = new_host
|
133
|
+
parsed.path = new_path
|
134
|
+
parsed.scheme = hints[:scheme]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
return parsed
|
139
|
+
end
|
140
|
+
|
121
141
|
# Converts a path to a file protocol URI. If the path supplied is
|
122
142
|
# relative, it will be returned as a relative URI. If the path supplied
|
123
143
|
# is actually a URI, it will return the parsed URI.
|
@@ -458,15 +478,14 @@ module Addressable
|
|
458
478
|
@password = password
|
459
479
|
@host = host
|
460
480
|
@specified_port = port.to_s
|
461
|
-
@port = port
|
462
|
-
@port = @port.to_s if @port.kind_of?(Fixnum)
|
481
|
+
@port = port.kind_of?(Fixnum) ? port.to_s : port
|
463
482
|
if @port != nil && !(@port =~ /^\d+$/)
|
464
483
|
raise InvalidURIError,
|
465
484
|
"Invalid port number: #{@port.inspect}"
|
466
485
|
end
|
467
486
|
@port = @port.to_i
|
468
487
|
@port = nil if @port == 0
|
469
|
-
@path = path
|
488
|
+
@path = (path || "")
|
470
489
|
@query = query
|
471
490
|
@fragment = fragment
|
472
491
|
|
@@ -529,15 +548,15 @@ module Addressable
|
|
529
548
|
|
530
549
|
# Returns the username and password segment of this URI.
|
531
550
|
def userinfo
|
532
|
-
if !defined?(@userinfo) || @userinfo
|
551
|
+
if !defined?(@userinfo) || @userinfo == nil
|
533
552
|
current_user = self.user
|
534
553
|
current_password = self.password
|
535
|
-
if current_user
|
554
|
+
if !current_user && !current_password
|
536
555
|
@userinfo = nil
|
537
|
-
elsif current_user
|
538
|
-
@userinfo = "#{current_user}"
|
539
|
-
elsif current_user != nil && current_password != nil
|
556
|
+
elsif current_user && current_password
|
540
557
|
@userinfo = "#{current_user}:#{current_password}"
|
558
|
+
elsif current_user && !current_password
|
559
|
+
@userinfo = "#{current_user}"
|
541
560
|
end
|
542
561
|
end
|
543
562
|
return @userinfo
|
@@ -593,9 +612,9 @@ module Addressable
|
|
593
612
|
|
594
613
|
# Sets the authority segment of this URI.
|
595
614
|
def authority=(new_authority)
|
596
|
-
if new_authority
|
615
|
+
if new_authority
|
597
616
|
new_userinfo = new_authority.scan(/^([^\[\]]*)@/).flatten[0]
|
598
|
-
if new_userinfo
|
617
|
+
if new_userinfo
|
599
618
|
new_user = new_userinfo.strip.scan(/^([^:]*):?/).flatten[0]
|
600
619
|
new_password = new_userinfo.strip.scan(/:(.*)$/).flatten[0]
|
601
620
|
end
|
@@ -604,7 +623,6 @@ module Addressable
|
|
604
623
|
new_port =
|
605
624
|
new_authority.scan(/:([^:@\[\]]*?)$/).flatten[0]
|
606
625
|
end
|
607
|
-
new_port = nil if new_port == ""
|
608
626
|
|
609
627
|
# Password assigned first to ensure validity in case of nil
|
610
628
|
self.password = new_password
|
@@ -654,10 +672,10 @@ module Addressable
|
|
654
672
|
# in the URI.
|
655
673
|
def port
|
656
674
|
if @port.to_i == 0
|
657
|
-
if self.scheme
|
658
|
-
@port = nil
|
659
|
-
else
|
675
|
+
if self.scheme
|
660
676
|
@port = self.class.scheme_mapping[self.scheme.strip.downcase]
|
677
|
+
else
|
678
|
+
@port = nil
|
661
679
|
end
|
662
680
|
return @port
|
663
681
|
else
|
@@ -690,13 +708,13 @@ module Addressable
|
|
690
708
|
|
691
709
|
# Sets the path for this URI.
|
692
710
|
def path=(new_path)
|
693
|
-
@path = new_path
|
711
|
+
@path = (new_path || "")
|
694
712
|
end
|
695
713
|
|
696
714
|
# Returns the basename, if any, of the file at the path being referenced.
|
697
715
|
# Returns nil if there is no path component.
|
698
716
|
def basename
|
699
|
-
|
717
|
+
# Path cannot be nil
|
700
718
|
return File.basename(self.path).gsub(/;[^\/]*$/, "")
|
701
719
|
end
|
702
720
|
|
@@ -704,8 +722,8 @@ module Addressable
|
|
704
722
|
# Returns "" if there is no extension or nil if there is no path
|
705
723
|
# component.
|
706
724
|
def extname
|
707
|
-
return nil
|
708
|
-
return File.extname(self.basename
|
725
|
+
return nil unless self.path
|
726
|
+
return File.extname(self.basename)
|
709
727
|
end
|
710
728
|
|
711
729
|
# Returns the query string for this URI.
|
@@ -730,8 +748,11 @@ module Addressable
|
|
730
748
|
|
731
749
|
# Returns true if the URI uses an IP-based protocol.
|
732
750
|
def ip_based?
|
733
|
-
|
734
|
-
|
751
|
+
if self.scheme
|
752
|
+
return self.class.ip_based_schemes.include?(
|
753
|
+
self.scheme.strip.downcase)
|
754
|
+
end
|
755
|
+
return false
|
735
756
|
end
|
736
757
|
|
737
758
|
# Returns true if this URI is known to be relative.
|
@@ -851,19 +872,18 @@ module Addressable
|
|
851
872
|
# supplied URI as a base for resolution. Returns an absolute URI if
|
852
873
|
# necessary.
|
853
874
|
def route_from(uri)
|
854
|
-
uri =
|
855
|
-
uri = uri.normalize
|
875
|
+
uri = self.class.parse(uri).normalize
|
856
876
|
normalized_self = self.normalize
|
857
877
|
if normalized_self.relative?
|
858
878
|
raise ArgumentError, "Expected absolute URI, got: #{self.to_s}"
|
859
879
|
end
|
860
880
|
if uri.relative?
|
861
|
-
raise ArgumentError, "Expected absolute URI, got: #{
|
881
|
+
raise ArgumentError, "Expected absolute URI, got: #{uri.to_s}"
|
862
882
|
end
|
863
883
|
if normalized_self == uri
|
864
884
|
return Addressable::URI.parse("##{normalized_self.fragment}")
|
865
885
|
end
|
866
|
-
segments = normalized_self.
|
886
|
+
segments = normalized_self.to_hash
|
867
887
|
if normalized_self.scheme == uri.scheme
|
868
888
|
segments[:scheme] = nil
|
869
889
|
if normalized_self.authority == uri.authority
|
@@ -876,11 +896,16 @@ module Addressable
|
|
876
896
|
if normalized_self.query == uri.query
|
877
897
|
segments[:query] = nil
|
878
898
|
end
|
899
|
+
else
|
900
|
+
if uri.path != "/"
|
901
|
+
segments[:path].gsub!(
|
902
|
+
Regexp.new("^" + Regexp.escape(uri.path)), "")
|
903
|
+
end
|
879
904
|
end
|
880
905
|
end
|
881
906
|
end
|
882
907
|
# Avoid network-path references.
|
883
|
-
if segments[:
|
908
|
+
if segments[:host] != nil
|
884
909
|
segments[:scheme] = normalized_self.scheme
|
885
910
|
end
|
886
911
|
return Addressable::URI.new(
|
@@ -899,8 +924,7 @@ module Addressable
|
|
899
924
|
# uses this URI as a base for resolution. Returns an absolute URI if
|
900
925
|
# necessary.
|
901
926
|
def route_to(uri)
|
902
|
-
|
903
|
-
return uri.route_from(self)
|
927
|
+
return self.class.parse(uri).route_from(self)
|
904
928
|
end
|
905
929
|
|
906
930
|
# Returns a normalized URI object.
|
@@ -925,8 +949,10 @@ module Addressable
|
|
925
949
|
normalized_password = nil
|
926
950
|
normalized_password = self.password.strip if self.password != nil
|
927
951
|
|
952
|
+
# If we are using http or https and user/password are blank,
|
953
|
+
# then we remove them
|
928
954
|
if normalized_scheme =~ /https?/ && normalized_user == "" &&
|
929
|
-
(normalized_password
|
955
|
+
(!normalized_password || normalized_password == "")
|
930
956
|
normalized_user = nil
|
931
957
|
normalized_password = nil
|
932
958
|
end
|
@@ -943,18 +969,13 @@ module Addressable
|
|
943
969
|
normalized_host = normalized_host[0...-1]
|
944
970
|
end
|
945
971
|
end
|
946
|
-
|
972
|
+
|
947
973
|
normalized_port = self.port
|
948
974
|
if self.class.scheme_mapping[normalized_scheme] == normalized_port
|
949
975
|
normalized_port = nil
|
950
976
|
end
|
951
977
|
normalized_path = nil
|
952
978
|
normalized_path = self.path.strip if self.path != nil
|
953
|
-
if normalized_path == nil &&
|
954
|
-
normalized_scheme != nil &&
|
955
|
-
normalized_host != nil
|
956
|
-
normalized_path = "/"
|
957
|
-
end
|
958
979
|
if normalized_path != nil
|
959
980
|
normalized_path = self.class.normalize_path(normalized_path)
|
960
981
|
end
|
@@ -1005,13 +1026,12 @@ module Addressable
|
|
1005
1026
|
# both URIs before doing the comparison, and allows comparison against
|
1006
1027
|
# strings.
|
1007
1028
|
def ===(uri)
|
1008
|
-
uri_string = nil
|
1009
1029
|
if uri.respond_to?(:normalize)
|
1010
1030
|
uri_string = uri.normalize.to_s
|
1011
1031
|
else
|
1012
1032
|
begin
|
1013
1033
|
uri_string = URI.parse(uri.to_s).normalize.to_s
|
1014
|
-
rescue
|
1034
|
+
rescue InvalidURIError
|
1015
1035
|
return false
|
1016
1036
|
end
|
1017
1037
|
end
|
@@ -1034,21 +1054,14 @@ module Addressable
|
|
1034
1054
|
|
1035
1055
|
# Clones the URI object.
|
1036
1056
|
def dup
|
1037
|
-
duplicated_scheme = nil
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
duplicated_port = self.port
|
1046
|
-
duplicated_path = nil
|
1047
|
-
duplicated_path = self.path.dup if self.path != nil
|
1048
|
-
duplicated_query = nil
|
1049
|
-
duplicated_query = self.query.dup if self.query != nil
|
1050
|
-
duplicated_fragment = nil
|
1051
|
-
duplicated_fragment = self.fragment.dup if self.fragment != nil
|
1057
|
+
duplicated_scheme = self.scheme ? self.scheme.dup : nil
|
1058
|
+
duplicated_user = self.user ? self.user.dup : nil
|
1059
|
+
duplicated_password = self.password ? self.password.dup : nil
|
1060
|
+
duplicated_host = self.host ? self.host.dup : nil
|
1061
|
+
duplicated_port = self.specified_port
|
1062
|
+
duplicated_path = self.path ? self.path.dup : nil
|
1063
|
+
duplicated_query = self.query ? self.query.dup : nil
|
1064
|
+
duplicated_fragment = self.fragment ? self.fragment.dup : nil
|
1052
1065
|
duplicated_uri = Addressable::URI.new(
|
1053
1066
|
duplicated_scheme,
|
1054
1067
|
duplicated_user,
|
@@ -1059,8 +1072,6 @@ module Addressable
|
|
1059
1072
|
duplicated_query,
|
1060
1073
|
duplicated_fragment
|
1061
1074
|
)
|
1062
|
-
@specified_port = nil if !defined?(@specified_port)
|
1063
|
-
duplicated_uri.instance_variable_set("@specified_port", @specified_port)
|
1064
1075
|
return duplicated_uri
|
1065
1076
|
end
|
1066
1077
|
|
@@ -1076,7 +1087,7 @@ module Addressable
|
|
1076
1087
|
end
|
1077
1088
|
|
1078
1089
|
# Returns a Hash of the URI segments.
|
1079
|
-
def
|
1090
|
+
def to_hash
|
1080
1091
|
return {
|
1081
1092
|
:scheme => self.scheme,
|
1082
1093
|
:user => self.user,
|
@@ -1171,17 +1182,19 @@ module Addressable
|
|
1171
1182
|
|
1172
1183
|
# Ensures that the URI is valid.
|
1173
1184
|
def validate
|
1174
|
-
if self.scheme == nil && self.user == nil && self.password == nil &&
|
1175
|
-
self.host == nil && self.port == nil && self.path == nil &&
|
1176
|
-
self.query == nil && self.fragment == nil
|
1177
|
-
raise InvalidURIError, "All segments were nil."
|
1178
|
-
end
|
1179
1185
|
if self.scheme != nil &&
|
1180
1186
|
(self.host == nil || self.host == "") &&
|
1181
1187
|
(self.path == nil || self.path == "")
|
1182
1188
|
raise InvalidURIError,
|
1183
1189
|
"Absolute URI missing hierarchical segment."
|
1184
1190
|
end
|
1191
|
+
if self.host == nil
|
1192
|
+
if self.specified_port != nil ||
|
1193
|
+
self.user != nil ||
|
1194
|
+
self.password != nil
|
1195
|
+
raise InvalidURIError, "Hostname not supplied."
|
1196
|
+
end
|
1197
|
+
end
|
1185
1198
|
end
|
1186
1199
|
|
1187
1200
|
# Replaces the internal state of self with the specified URI's state.
|