From a571a13d44e6be499d4f0632c5db5eda972f4377 Mon Sep 17 00:00:00 2001 From: Fabian Cenedese Date: Tue, 30 Jun 2020 23:00:06 +0200 Subject: [PATCH] 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. --- src/common/filename.cpp | 9 ++++++--- tests/filename/filenametest.cpp | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 474f7fa1c1..51d8953974 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1518,10 +1518,13 @@ bool wxFileName::Normalize(int flags, continue; } - else // Normal case, go one step up. + else // Normal case, go one step up unless it's .. as well. { - m_dirs.pop_back(); - continue; + if (m_dirs.back() != wxT("..") ) + { + m_dirs.pop_back(); + continue; + } } } } diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index 1db0edc52d..12d2d571d7 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -355,6 +355,7 @@ void FileNameTestCase::TestNormalize() { "b/../bar", wxPATH_NORM_DOTS, "bar", 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 // when it is the first character in the file name