diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index c54d624cfe6e..0d8011f0b0fe 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>> { @@ -415,6 +421,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";