Skip to content

Commit

Permalink
Non special urls don't have to have a path anymore. Updated the testi…
Browse files Browse the repository at this point in the history
… and the path_segments to reflect it.
  • Loading branch information
o0Ignition0o committed Aug 16, 2019
1 parent 88688f6 commit f364b4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/path_segments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ pub struct PathSegmentsMut<'a> {
pub fn new(url: &mut Url) -> PathSegmentsMut {
let after_path = url.take_after_path();
let old_after_path_position = to_u32(url.serialization.len()).unwrap();
debug_assert!(url.byte_at(url.path_start) == b'/');
// Special urls always have a non empty path
if SchemeType::from(url.scheme()).is_special() {
debug_assert!(url.byte_at(url.path_start) == b'/');
} else {
debug_assert!(
url.serialization.len() == url.path_start as usize
|| url.byte_at(url.path_start) == b'/'
);
}
PathSegmentsMut {
after_first_slash: url.path_start as usize + "/".len(),
url,
Expand Down Expand Up @@ -212,7 +220,10 @@ impl<'a> PathSegmentsMut<'a> {
if matches!(segment, "." | "..") {
continue;
}
if parser.serialization.len() > path_start + 1 {
if parser.serialization.len() > path_start + 1
// Non special url's path might still be empty
|| parser.serialization.len() == path_start
{
parser.serialization.push('/');
}
let mut has_host = true; // FIXME account for this?
Expand Down
4 changes: 2 additions & 2 deletions tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ fn test_set_host() {
assert_eq!(url.as_str(), "foobar:/hello");

let mut url = Url::parse("foo://ș").unwrap();
assert_eq!(url.as_str(), "foo://%C8%99/");
assert_eq!(url.as_str(), "foo://%C8%99");
url.set_host(Some("goșu.ro")).unwrap();
assert_eq!(url.as_str(), "foo://go%C8%99u.ro/");
assert_eq!(url.as_str(), "foo://go%C8%99u.ro");
}

#[test]
Expand Down

0 comments on commit f364b4a

Please sign in to comment.