From 42d969af9df7f327f287b5d1009e149b2f8f448e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 6 Apr 2004 04:21:06 +0000 Subject: [PATCH] fix CollapsePath("../../foo") resulting in "foo" --- stepmania/src/RageUtil.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 943651bb55..f5c9bb784d 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -1034,6 +1034,8 @@ CString FixSlashes( CString sPath ) * foo///bar/// -> foo/bar/ * foo/bar/./baz -> foo/bar/baz * foo/bar/../baz -> foo/baz + * ../foo -> ../foo + * ../../foo -> ../../foo * ./foo -> foo (if bRemoveLeadingDot), ./foo (if !bRemoveLeadingDot) * ./ -> . * ./// -> . @@ -1049,9 +1051,15 @@ void CollapsePath( CString &sPath, bool bRemoveLeadingDot ) { if( as[i] == ".." && i != 0 ) { - as.erase( as.begin()+i-1 ); - as.erase( as.begin()+i-1 ); - i -= 2; + /* If the previous element is also "..", then we have a path beginning + * with multiple "../"--one .. can't eat another .., since that would + * 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() ) {