@@ -114,8 +114,9 @@ ada_really_inline bool shorten_path(std::string& path,
114114 }
115115
116116 // Remove path’s last item, if any.
117- if (!path.empty ()) {
118- path.erase (path.rfind (' /' ));
117+ size_t last_delimiter = path.rfind (' /' );
118+ if (last_delimiter != std::string::npos) {
119+ path.erase (last_delimiter);
119120 return true ;
120121 }
121122
@@ -142,8 +143,8 @@ ada_really_inline bool shorten_path(std::string_view& path,
142143 size_t slash_loc = path.rfind (' /' );
143144 if (slash_loc != std::string_view::npos) {
144145 path.remove_suffix (path.size () - slash_loc);
146+ return true ;
145147 }
146- return true ;
147148 }
148149
149150 return false ;
@@ -507,8 +508,9 @@ ada_really_inline void parse_prepared_path(std::string_view input,
507508 input.substr (previous_location, new_location - previous_location);
508509 previous_location = new_location + 1 ;
509510 if (path_view == " .." ) {
510- if (!path.empty ()) {
511- path.erase (path.rfind (' /' ));
511+ size_t last_delimiter = path.rfind (' /' );
512+ if (last_delimiter != std::string::npos) {
513+ path.erase (last_delimiter);
512514 }
513515 } else if (path_view != " ." ) {
514516 path += ' /' ;
@@ -539,8 +541,8 @@ ada_really_inline void parse_prepared_path(std::string_view input,
539541 ? path_buffer_tmp
540542 : path_view;
541543 if (unicode::is_double_dot_path_segment (path_buffer)) {
542- helpers::shorten_path (path, type);
543- if ( location == std::string_view::npos) {
544+ if (( helpers::shorten_path (path, type) || special) &&
545+ location == std::string_view::npos) {
544546 path += ' /' ;
545547 }
546548 } else if (unicode::is_single_dot_path_segment (path_buffer) &&
0 commit comments