summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2013-02-22 00:27:26 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2013-02-23 03:31:33 +0000
commit4a2b187503de7425150528faab568e520bd2474f (patch)
tree092c4ce6d36eb345d6864e8af6b84d8174f852e9 /sc
parent654f6c7b1b666fa8bfb32dc74740721824eaf0ae (diff)
resolved fdo#57841 ignore embedded NULL characters in CSV import
Change-Id: Ib0eb044f009227c0aa6e1bc520905d605323c3db (cherry picked from commit 8970e14d7494859c6079ef2a976416598823ba50) Reviewed-on: https://gerrit.libreoffice.org/2336 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/dbgui/scuiasciiopt.cxx2
-rw-r--r--sc/source/ui/docshell/impex.cxx19
-rw-r--r--sc/source/ui/inc/impex.hxx2
3 files changed, 23 insertions, 0 deletions
diff --git a/sc/source/ui/dbgui/scuiasciiopt.cxx b/sc/source/ui/dbgui/scuiasciiopt.cxx
index d39c2581ee41..54d5e92824a6 100644
--- a/sc/source/ui/dbgui/scuiasciiopt.cxx
+++ b/sc/source/ui/dbgui/scuiasciiopt.cxx
@@ -540,6 +540,8 @@ bool ScImportAsciiDlg::GetLine( sal_uLong nLine, rtl::OUString &rText )
if ( mpDatStream->GetError() == ERRCODE_IO_CANTSEEK )
mpDatStream->ResetError();
+ ScImportExport::EmbeddedNullTreatment( rText);
+
return bRet;
}
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 09ec1cd750cb..9734f72be791 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1335,6 +1335,8 @@ bool ScImportExport::ExtText2Doc( SvStream& rStrm )
if ( rStrm.IsEof() && aLine.isEmpty() )
break;
+ EmbeddedNullTreatment( aLine);
+
sal_Int32 nLineLen = aLine.getLength();
SCCOL nCol = nStartCol;
bool bMultiLine = false;
@@ -1478,6 +1480,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,
String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted,
bool& rbOverflowCell )
diff --git a/sc/source/ui/inc/impex.hxx b/sc/source/ui/inc/impex.hxx
index c42720658a96..8c7e36b26dbe 100644
--- a/sc/source/ui/inc/impex.hxx
+++ b/sc/source/ui/inc/impex.hxx
@@ -102,6 +102,8 @@ public:
bool IsUndo() const { return bUndo; }
void SetUndo( bool b ) { bUndo = b; }
+ SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
+
static bool IsFormatSupported( sal_uLong nFormat );
static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
String& rField, sal_Unicode cStr, const sal_Unicode* pSeps,