diff --git a/src/common/filename.cpp b/src/common/filename.cpp index 234ac80138..99f24f2e16 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -427,7 +427,7 @@ void wxFileName::Assign(const wxString& fullpathOrig, // always recognize fullpath as directory, even if it doesn't end with a // slash wxString fullpath = fullpathOrig; - if ( !wxEndsWithPathSeparator(fullpath) ) + if ( !fullpath.empty() && !wxEndsWithPathSeparator(fullpath) ) { fullpath += GetPathSeparator(format); } diff --git a/tests/filename/filenametest.cpp b/tests/filename/filenametest.cpp index 992a05a8bf..813079ca8e 100644 --- a/tests/filename/filenametest.cpp +++ b/tests/filename/filenametest.cpp @@ -49,6 +49,11 @@ static struct FileNameInfo wxPathFormat format; } filenames[] = { + // the empty string + { _T(""), _(""), _(""), _(""), _(""), false, wxPATH_UNIX }, + { _T(""), _(""), _(""), _(""), _(""), false, wxPATH_DOS }, + { _T(""), _(""), _(""), _(""), _(""), false, wxPATH_VMS }, + // Unix file names { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX }, { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX }, @@ -167,6 +172,24 @@ void FileNameTestCase::TestConstruction() fni.format), fn ); } } + + wxFileName fn; + + // empty strings + fn.AssignDir(wxEmptyString); + CPPUNIT_ASSERT( !fn.IsOk() ); + + fn.Assign(wxEmptyString); + CPPUNIT_ASSERT( !fn.IsOk() ); + + fn.Assign(wxEmptyString, wxEmptyString); + CPPUNIT_ASSERT( !fn.IsOk() ); + + fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString); + CPPUNIT_ASSERT( !fn.IsOk() ); + + fn.Assign(wxEmptyString, wxEmptyString, wxEmptyString, wxEmptyString); + CPPUNIT_ASSERT( !fn.IsOk() ); } void FileNameTestCase::TestComparison()