Fix wxFileName::MakeRelativeTo() for directory relatively to itself.
The expected result in this case is ".", but the filename became empty instead when wxPATH_NATIVE was used. Fix this by examining GetFormat(format), which takes care of mapping wxPATH_NATIVE to its real value, instead of wxPATH_NATIVE itself. Also add a unit test verifying that this works as expected. Closes #17010.
This commit is contained in:
@@ -577,6 +577,10 @@ Major new features in this release
|
|||||||
3.0.3: (released 2015-??-??)
|
3.0.3: (released 2015-??-??)
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
|
All:
|
||||||
|
|
||||||
|
- Fix wxFileName::MakeRelativeTo() for directory relatively to itself.
|
||||||
|
|
||||||
Unix:
|
Unix:
|
||||||
|
|
||||||
- Fix wxIPaddress::Hostname() failing if /etc/hosts contained very long names.
|
- Fix wxIPaddress::Hostname() failing if /etc/hosts contained very long names.
|
||||||
|
@@ -1832,15 +1832,27 @@ bool wxFileName::MakeRelativeTo(const wxString& pathBase, wxPathFormat format)
|
|||||||
m_dirs.Insert(wxT(".."), 0u);
|
m_dirs.Insert(wxT(".."), 0u);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( format == wxPATH_UNIX || format == wxPATH_DOS )
|
switch ( GetFormat(format) )
|
||||||
{
|
{
|
||||||
// a directory made relative with respect to itself is '.' under Unix
|
case wxPATH_NATIVE:
|
||||||
// and DOS, by definition (but we don't have to insert "./" for the
|
case wxPATH_MAX:
|
||||||
// files)
|
wxFAIL_MSG( wxS("unreachable") );
|
||||||
if ( m_dirs.IsEmpty() && IsDir() )
|
wxFALLTHROUGH;
|
||||||
{
|
|
||||||
m_dirs.Add(wxT('.'));
|
case wxPATH_UNIX:
|
||||||
}
|
case wxPATH_DOS:
|
||||||
|
// a directory made relative with respect to itself is '.' under
|
||||||
|
// Unix and DOS, by definition (but we don't have to insert "./"
|
||||||
|
// for the files)
|
||||||
|
if ( m_dirs.IsEmpty() && IsDir() )
|
||||||
|
{
|
||||||
|
m_dirs.Add(wxT('.'));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxPATH_MAC:
|
||||||
|
case wxPATH_VMS:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_relative = true;
|
m_relative = true;
|
||||||
|
@@ -133,6 +133,7 @@ private:
|
|||||||
CPPUNIT_TEST( TestSetPath );
|
CPPUNIT_TEST( TestSetPath );
|
||||||
CPPUNIT_TEST( TestStrip );
|
CPPUNIT_TEST( TestStrip );
|
||||||
CPPUNIT_TEST( TestNormalize );
|
CPPUNIT_TEST( TestNormalize );
|
||||||
|
CPPUNIT_TEST( TestRelative );
|
||||||
CPPUNIT_TEST( TestReplace );
|
CPPUNIT_TEST( TestReplace );
|
||||||
CPPUNIT_TEST( TestGetHumanReadable );
|
CPPUNIT_TEST( TestGetHumanReadable );
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
@@ -158,6 +159,7 @@ private:
|
|||||||
void TestSplit();
|
void TestSplit();
|
||||||
void TestSetPath();
|
void TestSetPath();
|
||||||
void TestStrip();
|
void TestStrip();
|
||||||
|
void TestRelative();
|
||||||
void TestNormalize();
|
void TestNormalize();
|
||||||
void TestReplace();
|
void TestReplace();
|
||||||
void TestGetHumanReadable();
|
void TestGetHumanReadable();
|
||||||
@@ -441,6 +443,21 @@ void FileNameTestCase::TestNormalize()
|
|||||||
#endif // __WINDOWS__
|
#endif // __WINDOWS__
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileNameTestCase::TestRelative()
|
||||||
|
{
|
||||||
|
wxFileName fn("a/b.cpp");
|
||||||
|
fn.MakeRelativeTo("a");
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "b.cpp", fn.GetFullPath() );
|
||||||
|
|
||||||
|
fn.AssignDir("a/b");
|
||||||
|
fn.MakeRelativeTo("a");
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "b/", fn.GetFullPath() );
|
||||||
|
|
||||||
|
fn.AssignDir("a");
|
||||||
|
fn.MakeRelativeTo("a");
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "./", fn.GetFullPath() );
|
||||||
|
}
|
||||||
|
|
||||||
void FileNameTestCase::TestReplace()
|
void FileNameTestCase::TestReplace()
|
||||||
{
|
{
|
||||||
static const struct FileNameTest
|
static const struct FileNameTest
|
||||||
|
Reference in New Issue
Block a user