Skip to content

Commit 52b29e1

Browse files
authored
Merge branch 'main' into main
2 parents a76192f + 4b9f1e6 commit 52b29e1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

url/src/parser.rs

+4-4
Original file line numberDiff line numberDiff 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();

url/tests/unit.rs

+8
Original file line numberDiff line numberDiff 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]
10351043
fn no_panic() {
10361044
let mut url = Url::parse("arhttpsps:/.//eom/dae.com/\\\\t\\:").unwrap();

0 commit comments

Comments
 (0)