Skip to content

Commit

Permalink
Prevent panic when calling url::Url::set_host with None.
Browse files Browse the repository at this point in the history
Fixes #243.
  • Loading branch information
frewsxcv committed Dec 2, 2016
1 parent 52234db commit f82eb26
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit f82eb26

Please sign in to comment.