@@ -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,31 @@ 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");
938
939
///
939
940
/// let url = Url::parse("ftp://[email protected] ")?;
940
- /// assert_eq!(url.password(), None );
941
+ /// assert_eq!(url.password(), "" );
941
942
///
942
943
/// let url = Url::parse("https://example.com")?;
943
- /// assert_eq!(url.password(), None );
944
+ /// assert_eq!(url.password(), "" );
944
945
/// # Ok(())
945
946
/// # }
946
947
/// # run().unwrap();
947
948
/// ```
948
- pub fn password ( & self ) -> Option < & str > {
949
+ pub fn password ( & self ) -> & str {
949
950
// This ':' is not the one marking a port number since a host can not be empty.
950
951
// (Except for file: URLs, which do not have port numbers.)
951
952
if self . has_authority ( )
952
953
&& self . username_end != self . serialization . len ( ) as u32
953
954
&& self . byte_at ( self . username_end ) == b':'
954
955
{
955
956
debug_assert ! ( self . byte_at( self . host_start - 1 ) == b'@' ) ;
956
- Some ( self . slice ( self . username_end + 1 ..self . host_start - 1 ) )
957
+ self . slice ( self . username_end + 1 ..self . host_start - 1 )
957
958
} else {
958
- None
959
+ ""
959
960
}
960
961
}
961
962
0 commit comments