@@ -9,6 +9,7 @@ Date: January 2012
99\*******************************************************************/
1010
1111#include < cerrno>
12+ #include < cassert>
1213
1314#if defined(__linux__) || \
1415 defined (__FreeBSD_kernel__) || \
@@ -276,10 +277,18 @@ std::string fileutl_normalise_path(std::string const& path)
276277{
277278 std::string result = path;
278279 std::replace (result.begin (),result.end (),' \\ ' ,' /' );
279- std::string::size_type pos = 0 ;
280+ std::string::size_type pos = 0ULL ;
281+ while ((pos = result.find (" //" ,0 )) != std::string::npos)
282+ result.replace (pos,2 ," /" );
280283 while ((pos = result.find (" /./" ,0 )) != std::string::npos)
281284 result.replace (pos,3 ," /" );
282- // TODO: more fixes should be applied (e.g. /../, //, etc.)
285+ while ((pos = result.find (" /../" ,0 )) != std::string::npos)
286+ {
287+ assert (pos != 0ULL );
288+ const std::string::size_type prev_pos = result.rfind (" /" ,pos-1ULL );
289+ assert (pos != std::string::npos);
290+ result.replace (prev_pos,pos - prev_pos + 4ULL ," /" );
291+ }
283292 return result;
284293}
285294
0 commit comments