Handle strings with embedded NULs in wxDataStream
Read/write the entire string and not just the part until the first NUL in it. Closes #17556.
This commit is contained in:
@@ -72,6 +72,7 @@ All:
|
||||
- Add wxFileType::GetExpandedCommand() (troelsk).
|
||||
- Make it easier to convert to/from UTF-8-encoded std::string (ARATA Mizuki).
|
||||
- Add support for loading dynamic lexer in wxStyledTextCtrl (New Pagodi).
|
||||
- Handle strings with embedded NULs in wxDataStream (Nitch).
|
||||
|
||||
All (GUI):
|
||||
|
||||
|
@@ -187,7 +187,7 @@ wxString wxDataInputStream::ReadString()
|
||||
if ( tmp )
|
||||
{
|
||||
m_input->Read(tmp.data(), len);
|
||||
ret = m_conv->cMB2WX(tmp.data());
|
||||
ret = m_conv->cMB2WC(tmp.data(), len, NULL);
|
||||
}
|
||||
#else
|
||||
wxStringBuffer buf(ret, len);
|
||||
@@ -590,10 +590,11 @@ void wxDataOutputStream::WriteString(const wxString& string)
|
||||
{
|
||||
#if wxUSE_UNICODE
|
||||
const wxWX2MBbuf buf = string.mb_str(*m_conv);
|
||||
size_t len = buf.length();
|
||||
#else
|
||||
const wxWX2MBbuf buf = string.mb_str();
|
||||
size_t len = string.size();
|
||||
#endif
|
||||
size_t len = strlen(buf);
|
||||
Write32(len);
|
||||
if (len > 0)
|
||||
m_output->Write(buf, len);
|
||||
|
@@ -39,6 +39,7 @@ private:
|
||||
CPPUNIT_TEST_SUITE( DataStreamTestCase );
|
||||
CPPUNIT_TEST( FloatRW );
|
||||
CPPUNIT_TEST( DoubleRW );
|
||||
CPPUNIT_TEST( StringRW );
|
||||
#if wxUSE_LONGLONG
|
||||
CPPUNIT_TEST( LongLongRW );
|
||||
#endif
|
||||
@@ -66,6 +67,7 @@ private:
|
||||
|
||||
void FloatRW();
|
||||
void DoubleRW();
|
||||
void StringRW();
|
||||
#if wxUSE_LONGLONG
|
||||
void LongLongRW();
|
||||
#endif
|
||||
@@ -236,6 +238,19 @@ void DataStreamTestCase::DoubleRW()
|
||||
CPPUNIT_ASSERT( TestFloatRW(21321343431.1232143432) == 21321343431.1232143432 );
|
||||
}
|
||||
|
||||
void DataStreamTestCase::StringRW()
|
||||
{
|
||||
wxString s(wxT("Test1"));
|
||||
CPPUNIT_ASSERT_EQUAL( TestRW(s), s );
|
||||
|
||||
s.append(2, wxT('\0'));
|
||||
s.append(wxT("Test2"));
|
||||
CPPUNIT_ASSERT_EQUAL( TestRW(s), s );
|
||||
|
||||
s = wxString::FromUTF8("\xc3\xbc"); // U+00FC LATIN SMALL LETTER U WITH DIAERESIS
|
||||
CPPUNIT_ASSERT_EQUAL( TestRW(s), s );
|
||||
}
|
||||
|
||||
#if wxUSE_LONGLONG
|
||||
void DataStreamTestCase::LongLongRW()
|
||||
{
|
||||
|
Reference in New Issue
Block a user