File tree 2 files changed +9
-2
lines changed
2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -729,8 +729,9 @@ impl Url {
729
729
/// # run().unwrap();
730
730
/// ```
731
731
pub fn username ( & self ) -> & str {
732
- if self . has_authority ( ) {
733
- self . slice ( self . scheme_end + ( "://" . len ( ) as u32 ) ..self . username_end )
732
+ let scheme_separator_len = "://" . len ( ) as u32 ;
733
+ if self . has_authority ( ) && self . username_end > self . scheme_end + scheme_separator_len {
734
+ self . slice ( self . scheme_end + scheme_separator_len..self . username_end )
734
735
} else {
735
736
""
736
737
}
Original file line number Diff line number Diff line change @@ -665,3 +665,9 @@ fn test_set_scheme_to_file_with_host() {
665
665
assert_eq ! ( url. to_string( ) , "http://localhost:6767/foo/bar" ) ;
666
666
assert_eq ! ( result, Err ( ( ) ) ) ;
667
667
}
668
+
669
+ #[ test]
670
+ fn no_panic ( ) {
671
+ let mut url = Url :: parse ( "arhttpsps:/.//eom/dae.com/\\ \\ t\\ :" ) . unwrap ( ) ;
672
+ url:: quirks:: set_hostname ( & mut url, "//eom/datcom/\\ \\ t\\ ://eom/data.cs" ) . unwrap ( ) ;
673
+ }
You can’t perform that action at this time.
0 commit comments