Commit be53718e authored by hybrid's avatar hybrid

Fix flattenFilename method.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2952 dfc29bdd-3216-0410-991c-e03cc46cb475
parent f2e91f0e
...@@ -538,6 +538,7 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root ...@@ -538,6 +538,7 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root
s32 lastpos = 0; s32 lastpos = 0;
s32 pos = 0; s32 pos = 0;
bool lastWasRealDir=false;
while ((pos = directory.findNext('/', lastpos)) >= 0) while ((pos = directory.findNext('/', lastpos)) >= 0)
{ {
...@@ -545,7 +546,11 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root ...@@ -545,7 +546,11 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root
if (subdir == "../") if (subdir == "../")
{ {
if (lastWasRealDir)
deletePathFromPath(dir, 2); deletePathFromPath(dir, 2);
else
dir.append(subdir);
lastWasRealDir=false;
} }
else if (subdir == "/") else if (subdir == "/")
{ {
...@@ -554,6 +559,7 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root ...@@ -554,6 +559,7 @@ io::path& CFileSystem::flattenFilename(io::path& directory, const io::path& root
else if (subdir != "./" ) else if (subdir != "./" )
{ {
dir.append(subdir); dir.append(subdir);
lastWasRealDir=true;
} }
lastpos = pos + 1; lastpos = pos + 1;
......
...@@ -4,6 +4,46 @@ using namespace irr; ...@@ -4,6 +4,46 @@ using namespace irr;
using namespace core; using namespace core;
using namespace io; using namespace io;
static bool testFlattenFilename(io::IFileSystem* fs)
{
bool result=true;
io::path tmpString="../tmp";
io::path refString="../tmp/";
fs->flattenFilename(tmpString);
if (tmpString != refString)
{
logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
result = false;
}
tmpString="tmp/tmp/../";
refString="tmp/";
fs->flattenFilename(tmpString);
if (tmpString != refString)
{
logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
result = false;
}
tmpString="tmp/tmp/..";
fs->flattenFilename(tmpString);
if (tmpString != refString)
{
logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
result = false;
}
tmpString="tmp/next/../third";
refString="tmp/third/";
fs->flattenFilename(tmpString);
if (tmpString != refString)
{
logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
result = false;
}
return result;
}
bool filesystem(void) bool filesystem(void)
{ {
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1)); IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
...@@ -52,5 +92,6 @@ bool filesystem(void) ...@@ -52,5 +92,6 @@ bool filesystem(void)
// remove it again to not affect other tests // remove it again to not affect other tests
device->getFileSystem()->removeFileArchive( device->getFileSystem()->getFileArchiveCount() ); device->getFileSystem()->removeFileArchive( device->getFileSystem()->getFileArchiveCount() );
result |= testFlattenFilename(fs);
return result; return result;
} }
Test suite pass at GMT Mon Nov 30 15:06:06 2009 Test suite pass at GMT Mon Nov 30 17:33:50 2009
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment