@@ -921,7 +921,8 @@ impl Url {
921
921
}
922
922
}
923
923
924
- /// Return the password for this URL, if any, as a percent-encoded ASCII string.
924
+ /// Return the password for this URL (typically the empty string)
925
+ /// as a percent-encoded ASCII string.
925
926
///
926
927
/// # Examples
927
928
///
@@ -931,31 +932,34 @@ impl Url {
931
932
///
932
933
/// # fn run() -> Result<(), ParseError> {
933
934
/// let url = Url::parse("ftp://rms:[email protected] ")?;
934
- /// assert_eq!(url.password(), Some( "secret123") );
935
+ /// assert_eq!(url.password(), "secret123");
935
936
///
936
937
/// let url = Url::parse("ftp://:[email protected] ")?;
937
- /// assert_eq!(url.password(), Some("secret123"));
938
+ /// assert_eq!(url.password(), "secret123");
939
+ ///
940
+ /// let url = Url::parse("ftp://rms:@example.com")?;
941
+ /// assert_eq!(url.password(), "");
938
942
///
939
943
/// let url = Url::parse("ftp://[email protected] ")?;
940
- /// assert_eq!(url.password(), None );
944
+ /// assert_eq!(url.password(), "" );
941
945
///
942
946
/// let url = Url::parse("https://example.com")?;
943
- /// assert_eq!(url.password(), None );
947
+ /// assert_eq!(url.password(), "" );
944
948
/// # Ok(())
945
949
/// # }
946
950
/// # run().unwrap();
947
951
/// ```
948
- pub fn password ( & self ) -> Option < & str > {
952
+ pub fn password ( & self ) -> & str {
949
953
// This ':' is not the one marking a port number since a host can not be empty.
950
954
// (Except for file: URLs, which do not have port numbers.)
951
955
if self . has_authority ( )
952
956
&& self . username_end != self . serialization . len ( ) as u32
953
957
&& self . byte_at ( self . username_end ) == b':'
954
958
{
955
959
debug_assert ! ( self . byte_at( self . host_start - 1 ) == b'@' ) ;
956
- Some ( self . slice ( self . username_end + 1 ..self . host_start - 1 ) )
960
+ self . slice ( self . username_end + 1 ..self . host_start - 1 )
957
961
} else {
958
- None
962
+ ""
959
963
}
960
964
}
961
965
0 commit comments