File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,9 @@ impl<'a> PathSegmentsMut<'a> {
123123 /// # run().unwrap();
124124 /// ```
125125 pub fn pop_if_empty ( & mut self ) -> & mut Self {
126+ if self . after_first_slash >= self . url . serialization . len ( ) {
127+ return self ;
128+ }
126129 if self . url . serialization [ self . after_first_slash ..] . ends_with ( '/' ) {
127130 self . url . serialization . pop ( ) ;
128131 }
@@ -135,6 +138,9 @@ impl<'a> PathSegmentsMut<'a> {
135138 ///
136139 /// Returns `&mut Self` so that method calls can be chained.
137140 pub fn pop ( & mut self ) -> & mut Self {
141+ if self . after_first_slash >= self . url . serialization . len ( ) {
142+ return self ;
143+ }
138144 let last_slash = self . url . serialization [ self . after_first_slash ..]
139145 . rfind ( '/' )
140146 . unwrap_or ( 0 ) ;
Original file line number Diff line number Diff line change @@ -671,3 +671,11 @@ fn no_panic() {
671671 let mut url = Url :: parse ( "arhttpsps:/.//eom/dae.com/\\ \\ t\\ :" ) . unwrap ( ) ;
672672 url:: quirks:: set_hostname ( & mut url, "//eom/datcom/\\ \\ t\\ ://eom/data.cs" ) . unwrap ( ) ;
673673}
674+
675+ #[ test]
676+ fn pop_if_empty_in_bounds ( ) {
677+ let mut url = Url :: parse ( "m://" ) . unwrap ( ) ;
678+ let mut segments = url. path_segments_mut ( ) . unwrap ( ) ;
679+ segments. pop_if_empty ( ) ;
680+ segments. pop ( ) ;
681+ }
You can’t perform that action at this time.
0 commit comments