|
|
@@ -322,6 +322,32 @@ impl Url {
|
|
|
url
|
|
|
}
|
|
|
|
|
|
+ /// https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path
|
|
|
+ fn strip_trailing_spaces_from_opaque_path(&mut self) {
|
|
|
+ if !self.cannot_be_a_base() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.fragment_start.is_some() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if self.query_start.is_some() {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ let trailing_space_count = self
|
|
|
+ .serialization
|
|
|
+ .chars()
|
|
|
+ .rev()
|
|
|
+ .take_while(|c| *c == ' ')
|
|
|
+ .count();
|
|
|
+
|
|
|
+ let start = self.serialization.len() - trailing_space_count;
|
|
|
+
|
|
|
+ self.serialization.truncate(start);
|
|
|
+ }
|
|
|
+
|
|
|
/// Parse a string as an URL, with this URL as the base URL.
|
|
|
///
|
|
|
/// The inverse of this is [`make_relative`].
|
|
|
@@ -1434,7 +1460,8 @@ impl Url {
|
|
|
self.serialization.push('#');
|
|
|
self.mutate(|parser| parser.parse_fragment(parser::Input::no_trim(input)))
|
|
|
} else {
|
|
|
- self.fragment_start = None
|
|
|
+ self.fragment_start = None;
|
|
|
+ self.strip_trailing_spaces_from_opaque_path();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1497,6 +1524,9 @@ impl Url {
|
|
|
parser::Input::trim_tab_and_newlines(input, vfn),
|
|
|
)
|
|
|
});
|
|
|
+ } else {
|
|
|
+ self.query_start = None;
|
|
|
+ self.strip_trailing_spaces_from_opaque_path();
|
|
|
}
|
|
|
|
|
|
self.restore_already_parsed_fragment(fragment);
|