Skip to content

Commit 15e0ef7

Browse files
committed
A special url always has a path. A path always starts with '/'
1 parent 384a516 commit 15e0ef7

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/parser.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,24 @@ impl<'a> Parser<'a> {
780780
self.serialization.push_str(before_query);
781781
// FIXME spec says just "remove last entry", not the "pop" algorithm
782782
self.pop_path(scheme_type, base_url.path_start as usize);
783-
let remaining =
784-
self.parse_path(scheme_type, &mut true, base_url.path_start as usize, input);
783+
// A special url always has a path.
784+
// A path always starts with '/'
785+
if self.serialization.len() == base_url.path_start as usize {
786+
if SchemeType::from(base_url.scheme()).is_special() || !input.is_empty() {
787+
self.serialization.push('/');
788+
}
789+
}
790+
let remaining = match input.split_first() {
791+
(Some('/'), remaining) => self.parse_path(
792+
scheme_type,
793+
&mut true,
794+
base_url.path_start as usize,
795+
remaining,
796+
),
797+
_ => {
798+
self.parse_path(scheme_type, &mut true, base_url.path_start as usize, input)
799+
}
800+
};
785801
self.with_query_and_fragment(
786802
scheme_type,
787803
base_url.scheme_end,

0 commit comments

Comments
 (0)