Skip to content

Commit 3e4557c

Browse files
committed
Non special urls don't have to have a path anymore. Updated the testi and the path_segments to reflect it.
1 parent 4018195 commit 3e4557c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/path_segments.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,15 @@ pub struct PathSegmentsMut<'a> {
4545
pub fn new(url: &mut Url) -> PathSegmentsMut {
4646
let after_path = url.take_after_path();
4747
let old_after_path_position = to_u32(url.serialization.len()).unwrap();
48-
debug_assert!(url.byte_at(url.path_start) == b'/');
48+
// Special urls always have a non empty path
49+
if SchemeType::from(url.scheme()).is_special() {
50+
debug_assert!(url.byte_at(url.path_start) == b'/');
51+
} else {
52+
debug_assert!(
53+
url.serialization.len() == url.path_start as usize
54+
|| url.byte_at(url.path_start) == b'/'
55+
);
56+
}
4957
PathSegmentsMut {
5058
after_first_slash: url.path_start as usize + "/".len(),
5159
url: url,
@@ -212,7 +220,10 @@ impl<'a> PathSegmentsMut<'a> {
212220
if matches!(segment, "." | "..") {
213221
continue;
214222
}
215-
if parser.serialization.len() > path_start + 1 {
223+
if parser.serialization.len() > path_start + 1
224+
// Non special url's path might still be empty
225+
|| parser.serialization.len() == path_start
226+
{
216227
parser.serialization.push('/');
217228
}
218229
let mut has_host = true; // FIXME account for this?

tests/unit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,9 @@ fn test_set_host() {
413413
assert_eq!(url.as_str(), "foobar:/hello");
414414

415415
let mut url = Url::parse("foo://ș").unwrap();
416-
assert_eq!(url.as_str(), "foo://%C8%99/");
416+
assert_eq!(url.as_str(), "foo://%C8%99");
417417
url.set_host(Some("goșu.ro")).unwrap();
418-
assert_eq!(url.as_str(), "foo://go%C8%99u.ro/");
418+
assert_eq!(url.as_str(), "foo://go%C8%99u.ro");
419419
}
420420

421421
#[test]

0 commit comments

Comments
 (0)