diff options
| author | Daniel Patterson <dbp@riseup.net> | 2012-07-25 19:22:59 -0400 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-08-03 11:28:18 -0700 |
| commit | e349201bc26c2581e948aae53ac7701c34bef80c (patch) | |
| tree | 1a509f8fb619715663ca3215fd6a90eaa61e5129 /src/libstd | |
| parent | ef46314d1e6418b57a1d0a4efb5853dcaf8077d4 (diff) | |
std::net::url - comment cleanup, new test
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/net_url.rs | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index c54d624cfe6..0d8011f0b0f 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -78,7 +78,8 @@ fn encode_inner(s: ~str, full_url: bool) -> ~str { } } -/** Encodes a URI by replacing reserved characters with percent encoded character +/** + * Encodes a URI by replacing reserved characters with percent encoded character * sequences. * * This function is compliant with RFC 3986. @@ -87,7 +88,8 @@ fn encode(s: ~str) -> ~str { encode_inner(s, true) } -/** Encodes a URI component by replacing reserved characters with percent encoded +/** + * Encodes a URI component by replacing reserved characters with percent encoded * character sequences. * * This function is compliant with RFC 3986. @@ -134,7 +136,8 @@ fn decode_inner(s: ~str, full_url: bool) -> ~str { } } -/** Decode a string encoded with percent encoding. +/** + * Decode a string encoded with percent encoding. * * This will only decode escape sequences generated by encode_uri. */ @@ -142,7 +145,8 @@ fn decode(s: ~str) -> ~str { decode_inner(s, true) } -/** Decode a string encoded with percent encoding. +/** + * Decode a string encoded with percent encoding. */ fn decode_component(s: ~str) -> ~str { decode_inner(s, false) @@ -167,7 +171,8 @@ fn encode_plus(s: ~str) -> ~str { } } -/** Encode a hashmap to the 'application/x-www-form-urlencoded' media type. +/** + * Encode a hashmap to the 'application/x-www-form-urlencoded' media type. */ fn encode_form_urlencoded(m: hashmap<~str, @dvec<@~str>>) -> ~str { let mut out = ~""; @@ -191,7 +196,8 @@ fn encode_form_urlencoded(m: hashmap<~str, @dvec<@~str>>) -> ~str { out } -/** Decode a string encoded with the 'application/x-www-form-urlencoded' media +/** + * Decode a string encoded with the 'application/x-www-form-urlencoded' media * type into a hashmap. */ fn decode_form_urlencoded(s: ~[u8]) -> hashmap<~str, @dvec<@~str>> { @@ -416,6 +422,18 @@ impl of to_str::to_str for url { #[cfg(test)] mod tests { #[test] + fn test_url_parse() { + let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; + let u = result::unwrap(from_str(url)); + assert u.scheme == ~"http"; + assert option::unwrap(u.user).user == ~"user"; + assert option::unwrap(option::unwrap(u.user).pass) == ~"pass"; + assert u.host == ~"rust-lang.org"; + assert u.path == ~"/doc"; + assert u.query.get(~"s") == ~"v"; + assert option::unwrap(u.fragment) == "something"; + } + #[test] fn test_full_url_parse_and_format() { let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; assert to_str(result::unwrap(from_str(url))) == url; |
