Fix bug in wxFileName::Normalize() with leading ".."

Don't discard initial ".." when there is more than one such component in
the beginning of the path.

Closes #18800.
This commit is contained in:
Fabian Cenedese
2020-06-30 23:00:06 +02:00
committed by Vadim Zeitlin
parent ff87733cd8
commit a571a13d44
2 changed files with 7 additions and 3 deletions

View File

@@ -1518,13 +1518,16 @@ bool wxFileName::Normalize(int flags,
continue; continue;
} }
else // Normal case, go one step up. else // Normal case, go one step up unless it's .. as well.
{
if (m_dirs.back() != wxT("..") )
{ {
m_dirs.pop_back(); m_dirs.pop_back();
continue; continue;
} }
} }
} }
}
m_dirs.Add(dir); m_dirs.Add(dir);
} }

View File

@@ -355,6 +355,7 @@ void FileNameTestCase::TestNormalize()
{ "b/../bar", wxPATH_NORM_DOTS, "bar", wxPATH_UNIX }, { "b/../bar", wxPATH_NORM_DOTS, "bar", wxPATH_UNIX },
{ "c/../../quux", wxPATH_NORM_DOTS, "../quux", wxPATH_UNIX }, { "c/../../quux", wxPATH_NORM_DOTS, "../quux", wxPATH_UNIX },
{ "/c/../../quux", wxPATH_NORM_DOTS, "/quux", wxPATH_UNIX }, { "/c/../../quux", wxPATH_NORM_DOTS, "/quux", wxPATH_UNIX },
{ "../../quux", wxPATH_NORM_DOTS, "../../quux", wxPATH_UNIX },
// test wxPATH_NORM_TILDE: notice that ~ is only interpreted specially // test wxPATH_NORM_TILDE: notice that ~ is only interpreted specially
// when it is the first character in the file name // when it is the first character in the file name