Now stripping off trailing slashes and setting mFileSpec equal to nsnull when a bogus path

with double slashes is passed in.  Fixes bug 62861. r=dveditz, sr=mscott
This commit is contained in:
dbragg%netscape.com 2001-03-05 21:05:55 +00:00
parent 492e401e64
commit 53046cc8ad

View File

@ -505,7 +505,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe
break;
}
if (aRelativePath.Length() > 0 && mFileSpec)
if (mFileSpec && !aRelativePath.IsEmpty())
{
AppendXPPath(aRelativePath);
}
@ -519,19 +519,27 @@ nsInstallFolder::AppendXPPath(const nsString& aRelativePath)
PRInt32 start = 0;
PRInt32 curr;
NS_ASSERTION(!aRelativePath.IsEmpty(),"InstallFolder appending null path");
do {
curr = aRelativePath.FindChar('/',PR_FALSE,start);
if ( curr > start )
if ( curr == start )
{
// illegal, two slashes in a row (or not a relative path)
mFileSpec = nsnull;
break;
}
else if ( curr == kNotFound )
{
// last segment
aRelativePath.Mid(segment,start,-1);
start = aRelativePath.Length();
}
else
{
// found a segment
aRelativePath.Mid(segment,start,curr-start);
start = curr+1;
}
else
{
// last segment
aRelativePath.Mid(segment,start,-1);
}
nsresult rv = mFileSpec->AppendUnicode(segment.GetUnicode());
if (NS_FAILED(rv))
@ -542,7 +550,7 @@ nsInstallFolder::AppendXPPath(const nsString& aRelativePath)
tmp.AssignWithConversion(segment);
mFileSpec->Append(tmp.get());
}
} while ( curr != kNotFound );
} while ( start < aRelativePath.Length() );
}