Kaydet (Commit) 8970e14d authored tarafından Eike Rathke's avatar Eike Rathke

resolved fdo#57841 ignore embedded NULL characters in CSV import

Change-Id: Ib0eb044f009227c0aa6e1bc520905d605323c3db
üst 30fee57e
...@@ -540,6 +540,8 @@ bool ScImportAsciiDlg::GetLine( sal_uLong nLine, rtl::OUString &rText ) ...@@ -540,6 +540,8 @@ bool ScImportAsciiDlg::GetLine( sal_uLong nLine, rtl::OUString &rText )
if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK ) if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK )
mpDatStream->ResetError(); mpDatStream->ResetError();
ScImportExport::EmbeddedNullTreatment( rText);
return bRet; return bRet;
} }
......
...@@ -1335,6 +1335,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) ...@@ -1335,6 +1335,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
if ( rStrm.IsEof() && aLine.isEmpty() ) if ( rStrm.IsEof() && aLine.isEmpty() )
break; break;
EmbeddedNullTreatment( aLine);
sal_Int32 nLineLen = aLine.getLength(); sal_Int32 nLineLen = aLine.getLength();
SCCOL nCol = nStartCol; SCCOL nCol = nStartCol;
bool bMultiLine = false; bool bMultiLine = false;
...@@ -1473,6 +1475,23 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm ) ...@@ -1473,6 +1475,23 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
} }
void ScImportExport::EmbeddedNullTreatment( OUString & rStr )
{
// A nasty workaround for data with embedded NULL characters. As long as we
// can't handle them properly as cell content (things assume 0-terminated
// strings at too many places) simply strip all NULL characters from raw
// data. Excel does the same. See fdo#57841 for sample data.
// The normal case is no embedded NULL, check first before de-/allocating
// ustring stuff.
sal_Unicode cNull = 0;
if (rStr.indexOf( cNull) >= 0)
{
rStr = rStr.replaceAll( OUString( &cNull, 1), OUString());
}
}
const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p, const sal_Unicode* ScImportExport::ScanNextFieldFromString( const sal_Unicode* p,
String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted, String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted,
bool& rbOverflowCell ) bool& rbOverflowCell )
......
...@@ -102,6 +102,8 @@ public: ...@@ -102,6 +102,8 @@ public:
bool IsUndo() const { return bUndo; } bool IsUndo() const { return bUndo; }
void SetUndo( bool b ) { bUndo = b; } void SetUndo( bool b ) { bUndo = b; }
SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
static bool IsFormatSupported( sal_uLong nFormat ); static bool IsFormatSupported( sal_uLong nFormat );
static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p, static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, String& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment