File tree 2 files changed +12
-4
lines changed
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> {
398
398
}
399
399
400
400
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) {
402
403
return Err ( ( ) ) ;
403
404
}
404
405
debug_assert ! ( self . serialization. is_empty( ) ) ;
405
406
while let Some ( c) = input. next ( ) {
406
407
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 ( ) ) ,
410
410
':' => return Ok ( input) ,
411
411
_ => {
412
412
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() {
1031
1031
assert_eq ! ( result, Err ( ( ) ) ) ;
1032
1032
}
1033
1033
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
+
1034
1042
#[ test]
1035
1043
fn no_panic ( ) {
1036
1044
let mut url = Url :: parse ( "arhttpsps:/.//eom/dae.com/\\ \\ t\\ :" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments