@@ -322,6 +322,32 @@ impl Url {
322322 url
323323 }
324324
325+ /// https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path
326+ fn strip_trailing_spaces_from_opaque_path ( & mut self ) {
327+ if !self . cannot_be_a_base ( ) {
328+ return ;
329+ }
330+
331+ if self . fragment_start . is_some ( ) {
332+ return ;
333+ }
334+
335+ if self . query_start . is_some ( ) {
336+ return ;
337+ }
338+
339+ let trailing_space_count = self
340+ . serialization
341+ . chars ( )
342+ . rev ( )
343+ . take_while ( |c| * c == ' ' )
344+ . count ( ) ;
345+
346+ let start = self . serialization . len ( ) - trailing_space_count;
347+
348+ self . serialization . truncate ( start) ;
349+ }
350+
325351 /// Parse a string as an URL, with this URL as the base URL.
326352 ///
327353 /// The inverse of this is [`make_relative`].
@@ -1434,7 +1460,8 @@ impl Url {
14341460 self . serialization . push ( '#' ) ;
14351461 self . mutate ( |parser| parser. parse_fragment ( parser:: Input :: no_trim ( input) ) )
14361462 } else {
1437- self . fragment_start = None
1463+ self . fragment_start = None ;
1464+ self . strip_trailing_spaces_from_opaque_path ( ) ;
14381465 }
14391466 }
14401467
@@ -1497,6 +1524,9 @@ impl Url {
14971524 parser:: Input :: trim_tab_and_newlines ( input, vfn) ,
14981525 )
14991526 } ) ;
1527+ } else {
1528+ self . query_start = None ;
1529+ self . strip_trailing_spaces_from_opaque_path ( ) ;
15001530 }
15011531
15021532 self . restore_already_parsed_fragment ( fragment) ;
0 commit comments