Skip to content

Commit 24a68e3

Browse files
committed
add comment and unit test
1 parent 6e05d80 commit 24a68e3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

url/src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ impl<'a> Parser<'a> {
398398
}
399399

400400
pub fn parse_scheme<'i>(&mut self, mut input: Input<'i>) -> Result<Input<'i>, ()> {
401+
// starts_with will also fail for empty strings
402+
// so we can skip that comparison for perf
401403
if !input.starts_with(ascii_alpha) {
402404
return Err(());
403405
}

url/tests/unit.rs

Lines changed: 8 additions & 0 deletions
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)