fix CollapsePath("../../foo") resulting in "foo"

This commit is contained in:
Glenn Maynard
2004-04-06 04:21:06 +00:00
parent 9196f0521d
commit 42d969af9d
+11 -3
View File
@@ -1034,6 +1034,8 @@ CString FixSlashes( CString sPath )
* foo///bar/// -> foo/bar/ * foo///bar/// -> foo/bar/
* foo/bar/./baz -> foo/bar/baz * foo/bar/./baz -> foo/bar/baz
* foo/bar/../baz -> foo/baz * foo/bar/../baz -> foo/baz
* ../foo -> ../foo
* ../../foo -> ../../foo
* ./foo -> foo (if bRemoveLeadingDot), ./foo (if !bRemoveLeadingDot) * ./foo -> foo (if bRemoveLeadingDot), ./foo (if !bRemoveLeadingDot)
* ./ -> . * ./ -> .
* ./// -> . * ./// -> .
@@ -1049,9 +1051,15 @@ void CollapsePath( CString &sPath, bool bRemoveLeadingDot )
{ {
if( as[i] == ".." && i != 0 ) if( as[i] == ".." && i != 0 )
{ {
as.erase( as.begin()+i-1 ); /* If the previous element is also "..", then we have a path beginning
as.erase( as.begin()+i-1 ); * with multiple "../"--one .. can't eat another .., since that would
i -= 2; * cause "../../foo" to become "foo". */
if( as[i-1] != ".." )
{
as.erase( as.begin()+i-1 );
as.erase( as.begin()+i-1 );
i -= 2;
}
} }
else if( as[i] == "" && i != 0 && i+1 < as.size() ) else if( as[i] == "" && i != 0 && i+1 < as.size() )
{ {