File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -398,15 +398,15 @@ impl<'a> Parser<'a> {
398398 }
399399
400400 pub fn parse_scheme < ' i > ( & mut self , mut input : Input < ' i > ) -> Result < Input < ' i > , ( ) > {
401- if input. is_empty ( ) || !input. starts_with ( ascii_alpha) {
401+ // starts_with will also fail for empty strings so we can skip that comparison for perf
402+ if !input. starts_with ( ascii_alpha) {
402403 return Err ( ( ) ) ;
403404 }
404405 debug_assert ! ( self . serialization. is_empty( ) ) ;
405406 while let Some ( c) = input. next ( ) {
406407 match c {
407- 'a' ..='z' | 'A' ..='Z' | '0' ..='9' | '+' | '-' | '.' => {
408- self . serialization . push ( c. to_ascii_lowercase ( ) )
409- }
408+ 'a' ..='z' | '0' ..='9' | '+' | '-' | '.' => self . serialization . push ( c) ,
409+ 'A' ..='Z' => self . serialization . push ( c. to_ascii_lowercase ( ) ) ,
410410 ':' => return Ok ( input) ,
411411 _ => {
412412 self . serialization . clear ( ) ;
Original file line number Diff line number Diff line change @@ -1031,6 +1031,14 @@ fn test_set_scheme_to_file_with_host() {
10311031 assert_eq ! ( result, Err ( ( ) ) ) ;
10321032}
10331033
1034+ #[ test]
1035+ fn test_set_scheme_empty_err ( ) {
1036+ let mut url: Url = "http://localhost:6767/foo/bar" . parse ( ) . unwrap ( ) ;
1037+ let result = url. set_scheme ( "" ) ;
1038+ assert_eq ! ( url. to_string( ) , "http://localhost:6767/foo/bar" ) ;
1039+ assert_eq ! ( result, Err ( ( ) ) ) ;
1040+ }
1041+
10341042#[ test]
10351043fn no_panic ( ) {
10361044 let mut url = Url :: parse ( "arhttpsps:/.//eom/dae.com/\\ \\ t\\ :" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments