@@ -9,6 +9,7 @@ Date: January 2012
9
9
\*******************************************************************/
10
10
11
11
#include < cerrno>
12
+ #include < cassert>
12
13
13
14
#if defined(__linux__) || \
14
15
defined (__FreeBSD_kernel__) || \
@@ -276,10 +277,18 @@ std::string fileutl_normalise_path(std::string const& path)
276
277
{
277
278
std::string result = path;
278
279
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 ," /" );
280
283
while ((pos = result.find (" /./" ,0 )) != std::string::npos)
281
284
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
+ }
283
292
return result;
284
293
}
285
294
0 commit comments