Skip to content

Commit 3a31b7e

Browse files
committed
url: improve tests and docs for the authority method
Signed-off-by: Alejandro Martinez Ruiz <[email protected]>
1 parent 1dbc050 commit 3a31b7e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

url/src/lib.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ impl Url {
684684
/// Non-ASCII domains are punycode-encoded per IDNA if this is the host
685685
/// of a special URL, or percent encoded for non-special URLs.
686686
/// IPv6 addresses are given between `[` and `]` brackets.
687+
/// Ports are omitted if they match the well known port of a special URL.
687688
///
688689
/// Username and password are percent-encoded.
689690
///
@@ -702,10 +703,20 @@ impl Url {
702703
/// assert_eq!(url.authority(), "");
703704
/// let url = Url::parse("http://example.com/tmp/foo")?;
704705
/// assert_eq!(url.authority(), "example.com");
706+
/// let url = Url::parse("ftp://127.0.0.1:21/")?;
707+
/// assert_eq!(url.authority(), "127.0.0.1");
708+
/// let url = Url::parse("ftp://[email protected]:2121/")?;
709+
/// assert_eq!(url.authority(), "[email protected]:2121");
705710
/// let url = Url::parse("https://:@example.com/")?;
706711
/// assert_eq!(url.authority(), "example.com");
707-
/// let url = Url::parse("https://user:[email protected]:8080/tmp/foo")?;
708-
/// assert_eq!(url.authority(), "user:[email protected]:8080");
712+
/// let url = Url::parse("https://:password@[::1]:8080/")?;
713+
/// assert_eq!(url.authority(), ":password@[::1]:8080");
714+
/// let url = Url::parse("gopher://user:@àlex.example.com:70")?;
715+
/// assert_eq!(url.authority(), "user@%C3%A0lex.example.com:70");
716+
/// let url = Url::parse("irc://àlex:àlex@àlex.рф.example.com:6667/foo")?;
717+
/// assert_eq!(url.authority(), "%C3%A0lex:%C3%A0lex@%C3%A0lex.%D1%80%D1%84.example.com:6667");
718+
/// let url = Url::parse("https://àlex:àlex@àlex.рф.example.com:443/foo")?;
719+
/// assert_eq!(url.authority(), "%C3%A0lex:%C3%[email protected]");
709720
/// # Ok(())
710721
/// # }
711722
/// # run().unwrap();

0 commit comments

Comments
 (0)