Fix string iteration logic in wxFTP::Pwd()
wxString iterators can't be dereferenced once they reach the end of the string, so compare them with end rather than checking if the value they point to is non-NUL. This makes wxFTP::Pwd() actually work, which was apparently broken since quite some time (perhaps ever sincec9f7896861
9+ years ago). See #17679. (cherry picked from commitd0c57dbef0
)
This commit is contained in:
@@ -587,6 +587,7 @@ All:
|
|||||||
|
|
||||||
- Fix wxFileName::MakeRelativeTo() for directory relatively to itself.
|
- Fix wxFileName::MakeRelativeTo() for directory relatively to itself.
|
||||||
- Fix wxLocale::IsOk() return true even if setting the locale failed.
|
- Fix wxLocale::IsOk() return true even if setting the locale failed.
|
||||||
|
- Fix wxFTP::Pwd() to actually work.
|
||||||
- Null-terminate wxApp::argv for compatibility with the real argv.
|
- Null-terminate wxApp::argv for compatibility with the real argv.
|
||||||
|
|
||||||
Unix:
|
Unix:
|
||||||
|
@@ -459,20 +459,21 @@ wxString wxFTP::Pwd()
|
|||||||
{
|
{
|
||||||
// the result is at least that long if CheckCommand() succeeded
|
// the result is at least that long if CheckCommand() succeeded
|
||||||
wxString::const_iterator p = m_lastResult.begin() + LEN_CODE + 1;
|
wxString::const_iterator p = m_lastResult.begin() + LEN_CODE + 1;
|
||||||
if ( *p != wxT('"') )
|
const wxString::const_iterator end = m_lastResult.end();
|
||||||
|
if ( p == end || *p != wxT('"') )
|
||||||
{
|
{
|
||||||
wxLogDebug(wxT("Missing starting quote in reply for PWD: %s"),
|
wxLogDebug(wxT("Missing starting quote in reply for PWD: %s"),
|
||||||
wxString(p, m_lastResult.end()));
|
wxString(p, end));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ( ++p; (bool)*p; ++p ) // FIXME-DMARS
|
for ( ++p; p != end; ++p )
|
||||||
{
|
{
|
||||||
if ( *p == wxT('"') )
|
if ( *p == wxT('"') )
|
||||||
{
|
{
|
||||||
// check if the quote is doubled
|
// check if the quote is doubled
|
||||||
++p;
|
++p;
|
||||||
if ( !*p || *p != wxT('"') )
|
if ( p == end || *p != wxT('"') )
|
||||||
{
|
{
|
||||||
// no, this is the end
|
// no, this is the end
|
||||||
break;
|
break;
|
||||||
@@ -484,7 +485,7 @@ wxString wxFTP::Pwd()
|
|||||||
path += *p;
|
path += *p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !*p )
|
if ( p != end )
|
||||||
{
|
{
|
||||||
wxLogDebug(wxT("Missing ending quote in reply for PWD: %s"),
|
wxLogDebug(wxT("Missing ending quote in reply for PWD: %s"),
|
||||||
m_lastResult.c_str() + LEN_CODE + 1);
|
m_lastResult.c_str() + LEN_CODE + 1);
|
||||||
|
@@ -57,6 +57,7 @@ private:
|
|||||||
CPPUNIT_TEST( List );
|
CPPUNIT_TEST( List );
|
||||||
CPPUNIT_TEST( Download );
|
CPPUNIT_TEST( Download );
|
||||||
CPPUNIT_TEST( FileSize );
|
CPPUNIT_TEST( FileSize );
|
||||||
|
CPPUNIT_TEST( Pwd );
|
||||||
CPPUNIT_TEST( Misc );
|
CPPUNIT_TEST( Misc );
|
||||||
#ifndef FTP_ANONYMOUS
|
#ifndef FTP_ANONYMOUS
|
||||||
CPPUNIT_TEST( Upload );
|
CPPUNIT_TEST( Upload );
|
||||||
@@ -66,6 +67,7 @@ private:
|
|||||||
void List();
|
void List();
|
||||||
void Download();
|
void Download();
|
||||||
void FileSize();
|
void FileSize();
|
||||||
|
void Pwd();
|
||||||
void Misc();
|
void Misc();
|
||||||
void Upload();
|
void Upload();
|
||||||
|
|
||||||
@@ -148,9 +150,16 @@ void FTPTestCase::FileSize()
|
|||||||
CPPUNIT_ASSERT( size != -1 );
|
CPPUNIT_ASSERT( size != -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FTPTestCase::Pwd()
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "/", m_ftp->Pwd() );
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT( m_ftp->ChDir(directory) );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( directory, m_ftp->Pwd() );
|
||||||
|
}
|
||||||
|
|
||||||
void FTPTestCase::Misc()
|
void FTPTestCase::Misc()
|
||||||
{
|
{
|
||||||
|
|
||||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("STAT")) == '2' );
|
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("STAT")) == '2' );
|
||||||
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("HELP SITE")) == '2' );
|
CPPUNIT_ASSERT( m_ftp->SendCommand(wxT("HELP SITE")) == '2' );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user