diff --git a/src/lib.rs b/src/lib.rs index 89e08c3c2..2fca96310 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1003,7 +1003,7 @@ impl Url { debug_assert!(self.byte_at(self.scheme_end) == b':'); debug_assert!(self.byte_at(self.path_start) == b'/'); let new_path_start = self.scheme_end + 1; - self.serialization.drain(self.path_start as usize..new_path_start as usize); + self.serialization.drain(new_path_start as usize..self.path_start as usize); let offset = self.path_start - new_path_start; self.path_start = new_path_start; self.username_end = new_path_start; diff --git a/tests/unit.rs b/tests/unit.rs index eb460015d..93ad1440c 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -317,3 +317,12 @@ fn append_empty_segment_then_mutate() { url.assert_invariants(); assert_eq!(url.to_string(), "http://localhost:6767/foo/bar?a=b"); } + +#[test] +fn test_set_host() { + let mut url = Url::parse("https://example.net/hello").unwrap(); + url.set_host(Some("foo.com")).unwrap(); + assert_eq!(url.as_str(), "https://foo.com/hello"); + url.set_host(None).unwrap(); + assert_eq!(url.as_str(), "https:/hello"); +}