@@ -78,7 +78,8 @@ fn encode_inner(s: ~str, full_url: bool) -> ~str {
78
78
}
79
79
}
80
80
81
- /** Encodes a URI by replacing reserved characters with percent encoded character
81
+ /**
82
+ * Encodes a URI by replacing reserved characters with percent encoded character
82
83
* sequences.
83
84
*
84
85
* This function is compliant with RFC 3986.
@@ -87,7 +88,8 @@ fn encode(s: ~str) -> ~str {
87
88
encode_inner ( s, true )
88
89
}
89
90
90
- /** Encodes a URI component by replacing reserved characters with percent encoded
91
+ /**
92
+ * Encodes a URI component by replacing reserved characters with percent encoded
91
93
* character sequences.
92
94
*
93
95
* This function is compliant with RFC 3986.
@@ -134,15 +136,17 @@ fn decode_inner(s: ~str, full_url: bool) -> ~str {
134
136
}
135
137
}
136
138
137
- /** Decode a string encoded with percent encoding.
139
+ /**
140
+ * Decode a string encoded with percent encoding.
138
141
*
139
142
* This will only decode escape sequences generated by encode_uri.
140
143
*/
141
144
fn decode ( s : ~str ) -> ~str {
142
145
decode_inner ( s, true )
143
146
}
144
147
145
- /** Decode a string encoded with percent encoding.
148
+ /**
149
+ * Decode a string encoded with percent encoding.
146
150
*/
147
151
fn decode_component ( s : ~str ) -> ~str {
148
152
decode_inner ( s, false )
@@ -167,7 +171,8 @@ fn encode_plus(s: ~str) -> ~str {
167
171
}
168
172
}
169
173
170
- /** Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
174
+ /**
175
+ * Encode a hashmap to the 'application/x-www-form-urlencoded' media type.
171
176
*/
172
177
fn encode_form_urlencoded ( m : hashmap < ~str , @dvec < @~str > > ) -> ~str {
173
178
let mut out = ~"";
@@ -191,7 +196,8 @@ fn encode_form_urlencoded(m: hashmap<~str, @dvec<@~str>>) -> ~str {
191
196
out
192
197
}
193
198
194
- /** Decode a string encoded with the 'application/x-www-form-urlencoded' media
199
+ /**
200
+ * Decode a string encoded with the 'application/x-www-form-urlencoded' media
195
201
* type into a hashmap.
196
202
*/
197
203
fn decode_form_urlencoded( s : ~[ u8 ] ) -> hashmap < ~str , @dvec < @~str > > {
@@ -415,6 +421,18 @@ impl of to_str::to_str for url {
415
421
416
422
#[ cfg ( test) ]
417
423
mod tests {
424
+ #[ test]
425
+ fn test_url_parse( ) {
426
+ let url = ~"
http : //user:[email protected] /doc?s=v#something";
427
+ let u = result:: unwrap ( from_str ( url) ) ;
428
+ assert u. scheme == ~"http";
429
+ assert option:: unwrap ( u. user ) . user == ~"user";
430
+ assert option:: unwrap ( option:: unwrap ( u. user ) . pass ) == ~"pass";
431
+ assert u. host == ~"rust-lang. org";
432
+ assert u . path == ~"/doc";
433
+ assert u. query . get ( ~"s") == ~"v";
434
+ assert option:: unwrap ( u. fragment ) == "something" ;
435
+ }
418
436
#[ test]
419
437
fn test_full_url_parse_and_format( ) {
420
438
let url = ~"http
: //user:[email protected] /doc?s=v#something";
0 commit comments